appfw/apparchitecture/apserv/APSSES.CPP
changeset 0 2e3d3ce01487
child 15 312d2b433792
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // AppArc server session
       
    15 // 
       
    16 // apsses.cpp
       
    17 //
       
    18 
       
    19 #include <e32svr.h>
       
    20 #include <apacmdln.h>
       
    21 
       
    22 #include <apaflrec.h>
       
    23 #include "apsserv.h"
       
    24 #include "APSSES.H"
       
    25 #ifdef _DEBUG
       
    26 #include "APSSTD.H"
       
    27 #endif //_DEBUG
       
    28 #include "APSCLSV.H"
       
    29 #include <apsscan.h>
       
    30 #include <apgaplst.h>
       
    31 #include <apgicnfl.h>
       
    32 #include <apmrec.h>
       
    33 #include <apmstd.h>
       
    34 #include <apmfndr.h>
       
    35 #include <datastor.h>
       
    36 #include <s32mem.h>
       
    37 #include <s32strm.h>
       
    38 #include <s32file.h>
       
    39 #include "../apgrfx/apprivate.h"
       
    40 #include "apgnotif.h"
       
    41 #include "../aplist/aplappregfinder.h"
       
    42 #include "ApLaunchChecker.h"
       
    43 #include "apsnnapps.h"
       
    44 #include "../aplist/aplapplistitem.h"
       
    45 
       
    46 #include "apsecutils.h"
       
    47 
       
    48 const TInt KApaAppListServMaxBuffer=256;
       
    49 #include "APSRECCACHE.h"
       
    50 const TInt KApaAppInfoArrayGranularity = 4;
       
    51 const TInt KApaAppInfoDesMaxLength = sizeof(TApaAppInfo);
       
    52 
       
    53 #if defined(__PROFILE)
       
    54 _LIT(KProfileAppForDocumentL, "AppForDocumentL - %d.%06d seconds");
       
    55 _LIT(KProfileAppForDocumentPassedByFileHandleL, "AppForDocumentPassedByFileHandleL - %d.%06d seconds");
       
    56 #endif
       
    57 _LIT(KApaPanicCli,"APSERV-CLI");
       
    58 const TInt KFinishedScanning=-2;
       
    59 
       
    60 
       
    61 class MArrayItemWriter
       
    62 	{
       
    63 public:
       
    64 	virtual TInt ArrayItemCount() const=0;
       
    65 	virtual TInt ArrayItemSize() const=0;
       
    66 	virtual void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const=0;
       
    67 	};
       
    68 
       
    69 NONSHARABLE_CLASS(TSizeArrayItemWriter) : public MArrayItemWriter
       
    70 	{
       
    71 public:
       
    72 	inline TSizeArrayItemWriter(const CArrayFix<TSize>& aArray) : iArray(aArray) {}
       
    73 public: // from MArrayItemWriter
       
    74 	TInt ArrayItemCount() const;
       
    75 	TInt ArrayItemSize() const;
       
    76 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
       
    77 private:
       
    78 	const CArrayFix<TSize>& iArray;
       
    79 	};
       
    80 
       
    81 NONSHARABLE_CLASS(TViewDataArrayItemWriter) : public MArrayItemWriter
       
    82 	{
       
    83 public:
       
    84 	inline TViewDataArrayItemWriter(const CArrayPtr<CApaAppViewData>& aArray) : iArray(aArray) {}
       
    85 public:	// from MArrayItemWriter
       
    86 	TInt ArrayItemCount() const;
       
    87 	TInt ArrayItemSize() const;
       
    88 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
       
    89 private:
       
    90 	const CArrayPtr<CApaAppViewData>& iArray;
       
    91 	};
       
    92 
       
    93 NONSHARABLE_CLASS(TDesCArrayItemWriter) : public MArrayItemWriter
       
    94 	{
       
    95 public:
       
    96 	inline TDesCArrayItemWriter(const CDesCArray& aArray) : iArray(aArray) {}
       
    97 public:	// from MArrayItemWriter
       
    98 	TInt ArrayItemCount() const;
       
    99 	TInt ArrayItemSize() const;
       
   100 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
       
   101 private:
       
   102 	const CDesCArray& iArray;
       
   103 	};
       
   104 
       
   105 NONSHARABLE_CLASS(CApaAppListServSession::CApaAppInfo) : public CBase
       
   106 	{
       
   107 public:
       
   108 	CApaAppInfo();
       
   109 	~CApaAppInfo();
       
   110 	void SetUid(const TUid aUid);
       
   111 	void SetCaptionL(const TDesC& aCaption);
       
   112 	void SetShortCaptionL(const TDesC& aShortCaption);
       
   113 	void SetFullNameL(const TDesC& aFullName);
       
   114 	inline TPtrC Caption() const;
       
   115 	inline TPtrC ShortCaption() const;
       
   116 	inline TPtrC FullName() const;
       
   117 	inline TUid Uid() const;
       
   118 private:
       
   119 	TUid iUid;
       
   120 	HBufC* iCaption;
       
   121 	HBufC* iShortCaption;
       
   122 	HBufC* iFullName;
       
   123 	};
       
   124 
       
   125 inline TPtrC CApaAppListServSession::CApaAppInfo::Caption() const
       
   126 	{ return *iCaption; }
       
   127 
       
   128 inline TPtrC CApaAppListServSession::CApaAppInfo::ShortCaption() const
       
   129 	{ return *iShortCaption; }
       
   130 
       
   131 inline TPtrC CApaAppListServSession::CApaAppInfo::FullName() const
       
   132 	{ return *iFullName; }
       
   133 
       
   134 inline TUid CApaAppListServSession::CApaAppInfo::Uid() const
       
   135 	{ return iUid; }
       
   136 
       
   137 //
       
   138 // CApaAppListServSession
       
   139 //
       
   140 
       
   141 CApaAppListServSession* CApaAppListServSession::NewL(RFs& aFs, CApaAppArcServer& aAppArcSrv, CApaAppList& aAppList)
       
   142 	{
       
   143 	CApaAppListServSession* self = new (ELeave) CApaAppListServSession(aFs, aAppArcSrv, aAppList);
       
   144 	CleanupStack::PushL(self);
       
   145 	self->ConstructL();
       
   146 	CleanupStack::Pop(self);
       
   147 	return self;
       
   148 	}
       
   149 
       
   150 CApaAppListServSession::CApaAppListServSession(RFs& aFs, CApaAppArcServer& aAppArcSrv, CApaAppList& aAppList)
       
   151  : iFs(aFs), iAppArcSrv(aAppArcSrv), iAppList(aAppList), iApaAppInfoArray(KApaAppInfoArrayGranularity)
       
   152 	{
       
   153 
       
   154 	}
       
   155 
       
   156 void CApaAppListServSession::ConstructL()
       
   157 	{
       
   158 	iNonNativeApplicationsManager = CApsNonNativeApplicationsManager::NewL(iAppArcSrv,iFs);
       
   159 	}
       
   160 	
       
   161 
       
   162 CApaAppListServSession::~CApaAppListServSession()
       
   163 	{
       
   164 	delete iNonNativeApplicationsManager;
       
   165 	iApaAppInfoArray.ResetAndDestroy();
       
   166 	iApaAppInfoArray.Close();
       
   167 	}
       
   168 
       
   169 CApaAppList& CApaAppListServSession::AppList()
       
   170 	{
       
   171 	return iAppList;
       
   172 	}
       
   173 
       
   174 	
       
   175 void CApaAppListServSession::DoServiceL(const RMessage2& aMessage)
       
   176 	{
       
   177 	TBool completeMessage = ETrue;
       
   178 	const TInt opcode = aMessage.Function();
       
   179 	switch (opcode)
       
   180 		{
       
   181 	case ESetNotify:
       
   182 		SetNotify(aMessage);
       
   183 		completeMessage=EFalse;
       
   184 		break;
       
   185 	case ERegisterListPopulationCompleteObserver:
       
   186 		RegisterListPopulationCompleteObserver(aMessage);
       
   187 		completeMessage=EFalse;
       
   188 		break;
       
   189 	case ECancelListPopulationCompleteObserver:
       
   190 		CancelListPopulationCompleteObserver();
       
   191 		break;
       
   192 	case EAppListServInitFullList:
       
   193 		User::Leave(KErrNotSupported);
       
   194 	case EAppListServInitEmbedList:
       
   195 		User::Leave(KErrNotSupported);
       
   196 	case EAppListServInitFilteredEmbedList:
       
   197 		InitListL(aMessage,EListFilteredEmbeddedApps);
       
   198 		break;
       
   199 	case EAppListServInitAttrFilteredList:
       
   200 		InitListL(aMessage,EListCapabilityAttrFilteredApps);
       
   201 		break;
       
   202 	case EAppListServInitServerAppList:
       
   203 		InitListL(aMessage,EListServerApps);
       
   204 		break;
       
   205 	case EAppListServGetNextApp:
       
   206 		GetNextAppL(aMessage);
       
   207 		break;
       
   208 	case EAppListServEmbedCount:
       
   209 		EmbedCount(aMessage);
       
   210 		break;
       
   211 	case EAppListServAppCount:
       
   212 		AppCount(aMessage);
       
   213 		break;
       
   214 	case EAppListServGetAppInfo:
       
   215 		GetAppInfoL(aMessage);
       
   216 		break;
       
   217 	case EAppListServGetAppCapability:
       
   218 		GetAppCapabilityL(aMessage);
       
   219 		break;
       
   220 	case EAppListServGetDefaultScreenNumber:
       
   221 		GetDefaultScreenNumberL(aMessage);
       
   222 		break;
       
   223 	case EAppListServAppIconByUid:
       
   224 		IconForAppL(aMessage);
       
   225 		break;
       
   226 	case ECancelNotify:
       
   227 		CancelNotify();
       
   228 		break;
       
   229 	case EAppListServAppIconByUidAndSize:
       
   230 		IconForAppBySizeL(aMessage);
       
   231 		break;
       
   232 	case EAppListServAppIconFileHandle:
       
   233 		IconFileHandleForAppL(aMessage);
       
   234 		break;	
       
   235 	case EAppListServGetAppIconSizes:
       
   236 		AppIconSizesL(aMessage);
       
   237 		break;
       
   238 	case EAppListServViewIconByUidAndSize:
       
   239 		IconForViewBySizeL(aMessage);
       
   240 		break;
       
   241 	case EAppListServGetAppViews:
       
   242 		AppViewsL(aMessage);
       
   243 		break;
       
   244 	case EAppListServGetFileOwnershipInfo:
       
   245 		AppFileOwnershipInfoL(aMessage);
       
   246 		break;
       
   247 	case EAppListServNumberOfOwnDefinedIcons:
       
   248 		NumberOfOwnDefinedIconsL(aMessage);
       
   249 		break;
       
   250 	case EAppListServApplicationLanguage:
       
   251 		ApplicationLanguageL(aMessage);
       
   252 		break;
       
   253 	case EAppListServAppInfoProvidedByRegistrationFile: // private OpCode for CEikApplication's use only
       
   254 		AppInfoProvidedByRegistrationFileL(aMessage);
       
   255 		break;
       
   256 	case EAppListServAppIconFileName:
       
   257 		IconFileNameL(aMessage);
       
   258 		break;
       
   259 	case EAppListServAppViewIconFileName:
       
   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);
       
   441 		break;
       
   442 	case EAppListInsertDataMapping:
       
   443 	case EAppListInsertDataMappingIfHigher:
       
   444 		InsertDataMappingL(aMessage);
       
   445 		break;
       
   446 	case EAppListDeleteDataMapping:
       
   447 		DeleteDataMappingL(aMessage);
       
   448 		break;
       
   449 	case EAppListServGetAppByDataType:
       
   450 		GetAppByDataTypeL(aMessage);
       
   451 		break;		
       
   452 	case EAppListServGetAppServices:
       
   453 	case EAppListServGetServiceImplementations:
       
   454 	case EAppListServGetServiceImplementationsDataType:
       
   455 	case EAppListServGetAppServiceUids:
       
   456 	case EAppListServGetAppServiceOpaqueData:
       
   457 		GetAppServicesL(aMessage);
       
   458 		break;
       
   459 	case EAppListServAppForDataTypeAndService:
       
   460 		AppForDataTypeAndServiceL(aMessage);
       
   461 		break;
       
   462 	case EAppListServAppForDocumentAndService:
       
   463 		{
       
   464 		const TUid serviceUid=TUid::Uid(aMessage.Int1());
       
   465 		AppForDocumentL(aMessage, &serviceUid);
       
   466 		}
       
   467 		break;
       
   468 	case EAppListServAppForDocumentAndServicePassedByFileHandle:
       
   469 		{
       
   470 		const TUid serviceUid(TUid::Uid(aMessage.Int1()));
       
   471 		AppForDocumentPassedByFileHandleL(aMessage, &serviceUid);
       
   472 		}
       
   473 		break;
       
   474 	case EAppListServRegisterNonNativeApplicationType:
       
   475 		RegisterNonNativeApplicationTypeL(aMessage);
       
   476 		break;
       
   477 	case EAppListServDeregisterNonNativeApplicationType:
       
   478 		DeregisterNonNativeApplicationTypeL(aMessage);
       
   479 		break;
       
   480 	case EAppListServPreferredBufSize:
       
   481 		aMessage.Complete(PreferredBufSize());
       
   482 		break;
       
   483 	case EAppListServRecognizeFiles:
       
   484 		RecognizeFilesL(aMessage);
       
   485 		break;
       
   486 	case EAppListServTransferRecognitionResult:
       
   487 		TransferRecognitionResultL(aMessage);
       
   488 		break;
       
   489 	case EAppListServRecognizeFilesAsync:
       
   490 		RecognizeFilesAsyncL(aMessage);
       
   491 		completeMessage=EFalse;
       
   492 		break;
       
   493 	case ECancelRecognizeFiles:
       
   494 		CancelRecognizeFiles();
       
   495 		break;
       
   496 	case EAppListServRuleBasedLaunching:
       
   497 		AquirePermissionToLaunchAppL(aMessage);
       
   498 		break;
       
   499 	case ENotifyOnDataMappingChange:
       
   500 		NotifyOnDataMappingChange(aMessage);
       
   501 		completeMessage=EFalse;
       
   502 		break;
       
   503 	case ECancelNotifyOnDataMappingChange:
       
   504 		CancelNotifyOnDataMappingChange();
       
   505 		break;
       
   506 	case EDebugHeapMark:
       
   507 	#ifdef _DEBUG
       
   508 		__UHEAP_MARK;
       
   509 	#endif
       
   510 		break;
       
   511 	case EDebugHeapMarkEnd:
       
   512 	#ifdef _DEBUG
       
   513 		__UHEAP_MARKENDC(aMessage.Int0());
       
   514 	#endif
       
   515 		break;
       
   516 	case EDebugHeapFailNext:
       
   517 	#ifdef _DEBUG
       
   518 		__UHEAP_FAILNEXT(aMessage.Int0());
       
   519 	#endif
       
   520 		break;
       
   521 	case EDebugFlushRecognitionCache:
       
   522 	#ifdef _DEBUG
       
   523 		iServ.FlushRecognitionCache();
       
   524 	#endif
       
   525 		break;
       
   526 	case EDebugSetLoadRecognizersOnDemand:
       
   527 	#ifdef _DEBUG
       
   528 		iServ.SetLoadRecognizersOnDemandL(aMessage.Int0());
       
   529 	#endif
       
   530 		break;
       
   531 	case EDebugPerformOutstandingRecognizerUnloading:
       
   532 	#ifdef _DEBUG
       
   533 		iServ.PerformOutstandingRecognizerUnloading();
       
   534 		REComSession::FinalClose();
       
   535 	#endif
       
   536 		break;
       
   537 	default:
       
   538 		iAppListSession->DoServiceL(aMessage);
       
   539 		return;
       
   540 		}
       
   541 		
       
   542 	if (completeMessage && !aMessage.IsNull())
       
   543 		aMessage.Complete(KErrNone);
       
   544 	}
       
   545 
       
   546 
       
   547 void CApaAppArcServSession::NotifyOnDataMappingChange(const RMessage2& aMessage)
       
   548 	{ 
       
   549 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
       
   550 		aMessage.Panic(KApaPanicCli,ENotifyOnDataMappingChangeRequestOutstanding);
       
   551 	else
       
   552 		iMessage_NotifyOnDataMappingChange=aMessage;
       
   553 	}
       
   554 
       
   555 void CApaAppArcServSession::CancelNotifyOnDataMappingChange()
       
   556 	{
       
   557 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
       
   558 		iMessage_NotifyOnDataMappingChange.Complete(KErrCancel);
       
   559 	} //lint !e1762 Suppress member function could be made const
       
   560 
       
   561 
       
   562 TInt CApaAppArcServSession::PreferredBufSize() const
       
   563 	{
       
   564 	TInt preferredBufferSize = 0;
       
   565 	TRAPD(err, preferredBufferSize = iServ.DataRecognizerPreferredBufSizeL());
       
   566 	return (err==KErrNone) ? Min(iMaxBufSize, preferredBufferSize) : iMaxBufSize;
       
   567 	}
       
   568 
       
   569 void CApaAppArcServSession::RegisterNonNativeApplicationTypeL(const RMessage2& aMessage)
       
   570 	{
       
   571 	const TUid applicationType(TUid::Uid(aMessage.Int0()));
       
   572 	HBufC* const nativeExecutable=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
       
   573 	{TPtr nativeExecutable_asWritable(nativeExecutable->Des());
       
   574 	aMessage.ReadL(1, nativeExecutable_asWritable);}
       
   575 	iServ.RegisterNonNativeApplicationTypeL(applicationType, *nativeExecutable);
       
   576 	CleanupStack::PopAndDestroy(nativeExecutable);
       
   577 	}
       
   578 
       
   579 void CApaAppArcServSession::DeregisterNonNativeApplicationTypeL(const RMessage2& aMessage)
       
   580 	{
       
   581 	const TUid applicationType(TUid::Uid(aMessage.Int0()));
       
   582 	iServ.DeregisterNonNativeApplicationTypeL(applicationType);
       
   583 	}
       
   584 
       
   585 void CApaAppListServSession::GetAppTypeL(const RMessage2& aMessage)
       
   586 	{
       
   587 	TInt uid = aMessage.Int0();
       
   588 	CApaAppData* appData = iAppList.AppDataByUid(TUid::Uid(uid));
       
   589 	if (!appData)
       
   590 		aMessage.Complete(KErrNotFound);
       
   591 	else
       
   592 		{
       
   593 		TPckgBuf<TUid> typeUid(appData->NonNativeApplicationType());
       
   594 		aMessage.WriteL(1,typeUid);
       
   595 		aMessage.Complete(KErrNone);
       
   596 		}
       
   597 	}
       
   598 	
       
   599 void CApaAppListServSession::ForceRegistrationL(const RMessage2& aMessage)
       
   600 	{
       
   601 	TInt bufferSize = aMessage.GetDesLength(0);
       
   602 	User::LeaveIfError(bufferSize);
       
   603 	HBufC8* const buffer=HBufC8::NewLC(bufferSize);
       
   604 	TPtr8 buffer_asWritable(buffer->Des());
       
   605 	aMessage.ReadL(0,buffer_asWritable);
       
   606 		
       
   607 	RDesReadStream readStream(*buffer);
       
   608 	CleanupClosePushL(readStream);
       
   609 	const TUint count=readStream.ReadUint32L();
       
   610 	for (TUint i = 0; i < count; ++i)
       
   611 		{
       
   612 		TUint length = readStream.ReadUint32L();
       
   613 		HBufC* regFile = HBufC::NewLC(length);
       
   614   		TPtr ptr(regFile->Des());
       
   615   		readStream.ReadL(ptr, length);
       
   616 		iAppList.AddForcedRegistrationL(*regFile);
       
   617 		CleanupStack::PopAndDestroy(regFile);
       
   618 		}
       
   619 	
       
   620 	CleanupStack::PopAndDestroy(&readStream);
       
   621 	CleanupStack::PopAndDestroy(buffer);
       
   622 	
       
   623 	// Trigger a rescan, when rescan completes it will complete iNotifyOnScanCompleteMsg
       
   624 	iNotifyOnScanCompleteMsg=aMessage;
       
   625 	iAppArcSrv.UpdateAppsByForceRegistration();
       
   626 	}
       
   627 	
       
   628 void CApaAppArcServSession::AppForDocumentPassedByFileHandleL(const RMessage2& aMessage, const TUid* aServiceUid)
       
   629 	{
       
   630 #if defined(__PROFILE)
       
   631 	TProfile profile;
       
   632 	RDebug::ProfileReset(5,1);
       
   633 	RDebug::ProfileStart(5);
       
   634 #endif
       
   635 	RFile file;
       
   636 	CleanupClosePushL(file);
       
   637 	User::LeaveIfError(file.AdoptFromClient(aMessage, 2, 3));
       
   638 	SReturnData_AppForDocument returnData;
       
   639 	returnData.iDataType=iServ.RecognizeDataL(file, PreferredBufSize()).iDataType;
       
   640 	returnData.iUid=(returnData.iDataType!=TDataType())? AppForDataTypeL(returnData.iDataType, aServiceUid): TUid::Null();
       
   641 	CleanupStack::PopAndDestroy(&file);
       
   642 	aMessage.WriteL(0,TPckgC<SReturnData_AppForDocument>(returnData));
       
   643 #if defined(__PROFILE)
       
   644 	RDebug::ProfileEnd(5);
       
   645 	RDebug::ProfileResult(&profile,5,1);
       
   646 	RDebug::Print(KProfileAppForDocumentPassedByFileHandleL,profile.iTime/1000000,profile.iTime%1000000);
       
   647 	RDebug::ProfileStart(5);
       
   648 #endif
       
   649 	}
       
   650 
       
   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)
       
   656 	{
       
   657 #if defined(__PROFILE)
       
   658 	TProfile profile;
       
   659 	RDebug::ProfileReset(5,1);
       
   660 	RDebug::ProfileStart(5);
       
   661 #endif
       
   662 
       
   663 	// Get the document file name from the IPC message
       
   664 	HBufC* const docFileName = HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
       
   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)));
       
   670 	{TPtr8 buffer_asWritable(buffer->Des());
       
   671 	aMessage.ReadL(3,buffer_asWritable);}
       
   672 	
       
   673 	// Call the recognizer framework to get the MIME-type
       
   674 	SReturnData_AppForDocument returnData;
       
   675 	returnData.iDataType = iServ.RecognizeDataL(*docFileName, *buffer).iDataType;
       
   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 	
       
   679 #if defined(__PROFILE)
       
   680 	RDebug::ProfileEnd(5);
       
   681 	RDebug::ProfileResult(&profile,5,1);
       
   682 	RDebug::Print(KProfileAppForDocumentL,profile.iTime/1000000,profile.iTime%1000000);
       
   683 	RDebug::ProfileStart(5);
       
   684 #endif
       
   685 	
       
   686 	// Send back the answer
       
   687 	CleanupStack::PopAndDestroy(2, docFileName);
       
   688 	aMessage.WriteL(0,TPckgC<SReturnData_AppForDocument>(returnData));
       
   689 	}
       
   690 
       
   691 void CApaAppArcServSession::GetConfidenceL(const RMessage2& aMessage)
       
   692 // void GetAcceptedConfidence(TInt& aConfidence);
       
   693 	{
       
   694 	aMessage.WriteL(0,TPckgBuf<TInt>(iServ.MimeTypeRecognizer()->AcceptedConfidence()));
       
   695 	}
       
   696 
       
   697 void CApaAppArcServSession::SetConfidence(const RMessage2& aMessage)
       
   698 // SetAcceptedConfidence(TInt aConfidence);
       
   699 	{
       
   700 	__ASSERT_DEBUG(iServ.MimeTypeRecognizer(), Panic(EPanicNullPointer));
       
   701 	iServ.MimeTypeRecognizer()->SetAcceptedConfidence(aMessage.Int0());
       
   702 	}
       
   703 
       
   704 void CApaAppArcServSession::GetBufSize(const RMessage2& aMessage)
       
   705 // GetMaxDataBufSize(TInt& aBufSize);
       
   706 	{
       
   707 	aMessage.Complete(iMaxBufSize);
       
   708 	}
       
   709 
       
   710 void CApaAppArcServSession::SetBufSize(const RMessage2& aMessage)
       
   711 // SetMaxDataBufSize(TInt aBufSize);
       
   712 	{
       
   713 	iMaxBufSize=aMessage.Int0();
       
   714 	}
       
   715 
       
   716 void CApaAppArcServSession::GetDataTypesCountL(const RMessage2& aMessage)
       
   717 	{
       
   718 	delete iBuffer;
       
   719 	iBuffer = NULL;
       
   720 	CDataTypeArray* const dataTypes = new(ELeave) CDataTypeArray(5);
       
   721 	CleanupStack::PushL(dataTypes);
       
   722 	iServ.DataTypeL(*dataTypes);
       
   723 	
       
   724 	TInt completionCode=0; // not KErrNone, as completion code of zero tells the client that zero data types were found
       
   725 	if (dataTypes->Count()>0)
       
   726 		{
       
   727 		CBufBase* const buffer = CBufFlat::NewL(sizeof(TDataType)); 
       
   728 		CleanupStack::PushL(buffer); 
       
   729 		RBufWriteStream writeStream(*buffer); 
       
   730 		writeStream << *dataTypes; 
       
   731 		CleanupStack::Pop(buffer); 
       
   732 		iBuffer = buffer;
       
   733 		completionCode = iBuffer->Ptr(0).Size(); // number of bytes in buffer (not number of data types)
       
   734 		}
       
   735 	
       
   736 	CleanupStack::PopAndDestroy(dataTypes);
       
   737 	aMessage.Complete(completionCode);
       
   738 	}
       
   739 
       
   740 void CApaAppArcServSession::GetDataTypesL(const RMessage2& aMessage)
       
   741 // GetSupportedDataTypes(CDataTypeArray& aDataTypes);
       
   742 	{
       
   743 	if(!iBuffer)
       
   744 		aMessage.Panic(KApaPanicCli,ENoSupportedDataTypes);
       
   745 	else
       
   746 		{
       
   747 		aMessage.WriteL(0,iBuffer->Ptr(0));
       
   748 		delete iBuffer;
       
   749 		iBuffer=NULL;
       
   750 		}
       
   751 	}
       
   752 
       
   753 CApaAppData& CApaAppListServSession::FindAppInListL(TUid aUid)
       
   754 	{
       
   755 	TApaAppEntry dummy;
       
   756 	CApaAppData* app = NULL;
       
   757 	if (!FindAppInList(app, dummy, aUid))
       
   758 		User::Leave(KErrNotFound);
       
   759 
       
   760 	return *app;
       
   761 	}
       
   762 
       
   763 void CApaAppListServSession::SendArrayL(const MArrayItemWriter& aArrayItemWriter,const RMessage2& aMessage) const
       
   764 	{
       
   765 	const TInt sizeOfBuffer=aMessage.Int1();
       
   766 	const TInt arrayItemCount=aArrayItemWriter.ArrayItemCount();
       
   767 	const TInt sizeRequired=sizeof(TInt)+(arrayItemCount*aArrayItemWriter.ArrayItemSize());
       
   768 	ASSERT(sizeRequired > 0);
       
   769 	if (sizeRequired>sizeOfBuffer)
       
   770 		User::Leave(sizeRequired); // causes aMessage to complete with sizeRequired
       
   771 
       
   772 	CBufFlat* const buf=CBufFlat::NewL(sizeRequired);
       
   773 	CleanupStack::PushL(buf);
       
   774 	buf->ExpandL(0,sizeRequired);
       
   775 	RBufWriteStream writeStream;
       
   776 	writeStream.Open(*buf);
       
   777 	writeStream.WriteUint32L(arrayItemCount);
       
   778 	for (TInt i=0; i<arrayItemCount; ++i)
       
   779 		aArrayItemWriter.WriteArrayItemL(writeStream,i);
       
   780 
       
   781 	writeStream.CommitL();
       
   782 	aMessage.WriteL(2,buf->Ptr(0));
       
   783 	CleanupStack::PopAndDestroy(buf);
       
   784 	}
       
   785 
       
   786 void CApaAppListServSession::AppIconSizesL(const RMessage2& aMessage)
       
   787 	{
       
   788 	const TUid uid=TUid::Uid(aMessage.Int0());
       
   789 	const CApaAppData& app = FindAppInListL(uid);
       
   790 	if (app.NonMbmIconFile())
       
   791 		User::Leave(KErrNotSupported);
       
   792 		
       
   793 	CArrayFixFlat<TSize>* array = app.IconSizesL();
       
   794 	CleanupStack::PushL(array);
       
   795 	TSizeArrayItemWriter arrayItemWriter(*array);		
       
   796 	SendArrayL(arrayItemWriter, aMessage);
       
   797 	CleanupStack::PopAndDestroy(array);
       
   798 	}
       
   799 
       
   800 void CApaAppListServSession::AppViewsL(const RMessage2& aMessage)
       
   801 	{
       
   802 	const TUid uid=TUid::Uid(aMessage.Int0());
       
   803 	const CApaAppData& app = FindAppInListL(uid);
       
   804 	TViewDataArrayItemWriter arrayItemWriter(*app.Views());
       
   805 	SendArrayL(arrayItemWriter,aMessage);
       
   806 	}
       
   807 
       
   808 void CApaAppListServSession::AppFileOwnershipInfoL(const RMessage2& aMessage)
       
   809 	{
       
   810 	const TUid uid=TUid::Uid(aMessage.Int0());
       
   811 	const CApaAppData& app = FindAppInListL(uid);
       
   812 	TDesCArrayItemWriter arrayItemWriter(*app.OwnedFiles());
       
   813 	SendArrayL(arrayItemWriter,aMessage);
       
   814 	}
       
   815 
       
   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)
       
   897 	{
       
   898 	const TUid uid=TUid::Uid(aMessage.Int0());
       
   899 	TApaAppEntry entry;
       
   900 	CApaAppData* app=NULL;
       
   901 	if (!FindAppInList(app,entry,uid))
       
   902 		User::Leave(KErrNotFound);
       
   903 
       
   904 	TPtrC iconFileName = app->IconFileName();
       
   905 	if (iconFileName.Length()==0)
       
   906 		User::Leave(KErrNotFound);
       
   907 
       
   908 	RFs fs;
       
   909 	User::LeaveIfError(fs.Connect());
       
   910 	CleanupClosePushL(fs);
       
   911 	User::LeaveIfError(fs.ShareProtected());
       
   912 
       
   913 	RFile file;
       
   914 	CleanupClosePushL(file);
       
   915 	User::LeaveIfError(file.Open(fs, iconFileName, EFileShareReadersOnly));
       
   916 	User::LeaveIfError(file.TransferToClient(aMessage, 1));
       
   917 	CleanupStack::PopAndDestroy(2, &fs); //file and fs
       
   918 	}
       
   919 
       
   920 void CApaAppListServSession::IconForAppL(const RMessage2& aMessage)
       
   921 // from GetAppIcon(TUid aAppUid, TInt aSideInPixels, CApaMaskedBitmap& aAppBitmap);
       
   922 // BUT!  It's interface is uid, side, icon handle, mask handle for bitmap sharing 
       
   923 // and avoiding IPC overhead
       
   924 	{
       
   925 	const TUid uid = TUid::Uid(aMessage.Int0());
       
   926 	const CApaAppData& app = FindAppInListL(uid);
       
   927 
       
   928 	if (app.NonMbmIconFile())
       
   929 		User::Leave(KErrNotSupported);
       
   930 	
       
   931 	const TInt side = aMessage.Int1();
       
   932 	CApaMaskedBitmap* const icon = app.Icon(side);
       
   933 	if (!icon)
       
   934 		User::Leave(KErrNotFound);
       
   935 
       
   936 	SReturnData_AppIconByUid returnData;
       
   937 	returnData.iIcon = icon->Handle();
       
   938 	returnData.iIconMask = icon->Mask()->Handle();
       
   939 	aMessage.WriteL(2,TPckgC<SReturnData_AppIconByUid>(returnData));
       
   940 	}
       
   941 
       
   942 void CApaAppArcServSession::AppForDataTypeL(const RMessage2& aMessage)
       
   943 // from AppForDataType(const TDataType& aDataType, TUid& aAppUid);
       
   944 	{
       
   945 	if (sizeof(TDataType) != aMessage.GetDesLengthL(0))
       
   946 		{
       
   947 		//Leave with KErrArgument if client passes other than TDataType
       
   948 		User::Leave(KErrArgument);
       
   949 		}
       
   950 	TDataType dataType;
       
   951 	{TPckg<TDataType> dataType_asDescriptor(dataType);
       
   952 	aMessage.ReadL(0,dataType_asDescriptor);}
       
   953 	TPckgBuf<TUid> uid_asDescriptor(AppForDataTypeL(dataType, NULL));
       
   954 	aMessage.WriteL(1,uid_asDescriptor);
       
   955 	aMessage.Complete(KErrNone);
       
   956 	}
       
   957 
       
   958 void CApaAppArcServSession::AppForDataTypeAndServiceL(const RMessage2& aMessage)
       
   959 	{
       
   960 	TDataType dataType;
       
   961 	{TPckg<TDataType> dataType_asDescriptor(dataType);
       
   962 	aMessage.ReadL(0,dataType_asDescriptor);}
       
   963 	const TUid serviceUid=TUid::Uid(aMessage.Int1());
       
   964 	TPckgBuf<TUid> uid(AppForDataTypeL(dataType, &serviceUid));
       
   965 	aMessage.WriteL(2,uid);
       
   966 	aMessage.Complete(KErrNone);
       
   967 	}
       
   968 
       
   969 TUid CApaAppArcServSession::AppForDataTypeL(const TDataType& aDataType, const TUid* aServiceUid)
       
   970 	{
       
   971 	// It is possible to register apps as datatype handlers with system priority,
       
   972 	// which means that they are not overridable by user mappings.
       
   973 	// So search the list of apps for a datahandler and get the associated
       
   974 	// priority
       
   975 	 
       
   976 	TInt priority = KDataTypePriorityNormal;
       
   977 	TUid uid = iAppListSession->AppList().PreferredDataHandlerL(aDataType, aServiceUid, priority);
       
   978 	if (priority == KDataTypePrioritySystem)
       
   979 		return uid;	// We have found a handler with system priority
       
   980 		
       
   981 	// No handler with system priority so see if there is a user mapping
       
   982 	TUid userUid = KNullUid;
       
   983 	if (aServiceUid)
       
   984 		iServ.GetAppForMimeType(aDataType,*aServiceUid,userUid);
       
   985 	else
       
   986 		iServ.GetAppForMimeType(aDataType,userUid);
       
   987 
       
   988 	TApaAppEntry entry;
       
   989 	const CApaAppData* app = NULL;
       
   990 	if (userUid.iUid && iAppListSession->FindAppInList(app,entry,userUid))
       
   991 		return userUid;	// The user mapping is valid
       
   992 		
       
   993 	// A user mapping was not found or is invalid so try to use
       
   994 	// the uid returned by PreferredDataHandlerL.
       
   995 	if (!uid.iUid && aDataType.IsNative())
       
   996 		uid = aDataType.Uid();
       
   997 
       
   998 	return uid;
       
   999 	}
       
  1000 
       
  1001 void CApaAppArcServSession::InsertDataMappingL(const RMessage2& aMessage)
       
  1002 	{
       
  1003 	TPckgBuf<TDataType> dataType;
       
  1004 	aMessage.ReadL(0, dataType);
       
  1005 	TDataTypePriority priority = aMessage.Int1();
       
  1006 	const TUid appUid = { aMessage.Int2() };
       
  1007 
       
  1008 	if(priority>KDataTypeUnTrustedPriorityThreshold || priority == KDataTypePrioritySystem ) 
       
  1009 	   {   
       
  1010 	   CApaAppData* appData = iAppListSession->AppList().AppDataByUid(appUid);
       
  1011 	   if( appData )	
       
  1012 		  {
       
  1013           TBool hasWriteDeviceDataCap( EFalse );
       
  1014           TBool isSidTrusted( EFalse );
       
  1015           
       
  1016           CApaSecurityUtils::CheckAppSecurity( appData->AppEntry().iFullName, 
       
  1017                                                hasWriteDeviceDataCap,
       
  1018                                                isSidTrusted);
       
  1019           
       
  1020           if (priority == KDataTypePrioritySystem )
       
  1021               {
       
  1022               // Check if the app has capability WriteDeviceData
       
  1023               if ( !hasWriteDeviceDataCap )
       
  1024                   {
       
  1025                   priority = KDataTypePriorityNormal;
       
  1026                   }
       
  1027               }
       
  1028           else
       
  1029               {
       
  1030               TPtrC registrationFilePath = appData->RegistrationFileName();
       
  1031               TInt match = registrationFilePath.MatchF (
       
  1032                                           KLitPathForUntrustedRegistrationResourceFiles );
       
  1033               //Check if registration file is in path for untrusted apps 
       
  1034               //and its SID is untrusted
       
  1035               if (match != KErrNotFound && !isSidTrusted )
       
  1036                   {
       
  1037                   // "cap" the priority if UnTrusted apps claim for priority higher 
       
  1038                   // than UnTrusted apps Threshold priority
       
  1039                   priority = KDataTypeUnTrustedPriorityThreshold;
       
  1040                   }
       
  1041               }
       
  1042           }
       
  1043 	   else
       
  1044 		  {
       
  1045               //if the application is not present in the applist 
       
  1046               //then the priority will be reduced to Threshold
       
  1047               priority = KDataTypeUnTrustedPriorityThreshold;
       
  1048 		  }
       
  1049 	   }
       
  1050 
       
  1051 	const TUid serviceUid = { aMessage.Int3() };
       
  1052 	if(aMessage.Function() == EAppListInsertDataMappingIfHigher)
       
  1053 		{
       
  1054 		const TBool response = iServ.InsertAndStoreIfHigherL(dataType(), priority, appUid);
       
  1055 		aMessage.WriteL(3, TPckgC<TBool>(response));
       
  1056 		}
       
  1057 	else
       
  1058 		iServ.InsertAndStoreDataMappingL(dataType(), priority, appUid, serviceUid);
       
  1059 	}
       
  1060 
       
  1061 void CApaAppArcServSession::DeleteDataMappingL(const RMessage2& aMessage)
       
  1062 	{
       
  1063 	TPckgBuf<TDataType> dataType;
       
  1064 	aMessage.ReadL(0, dataType);
       
  1065 	const TUid serviceUid = { aMessage.Int1() };
       
  1066 	TUid uid;
       
  1067 	iServ.GetAppForMimeType(dataType(),serviceUid,uid);
       
  1068 	if (uid != KNullUid)
       
  1069 		{
       
  1070 		// TypeStore doesn't support deletion of an inexistent mapping
       
  1071 		iServ.DeleteAndStoreDataMappingL(dataType(), serviceUid);
       
  1072 		aMessage.Complete(KErrNone);
       
  1073 		}
       
  1074 	else
       
  1075 		aMessage.Complete(KErrNotFound);
       
  1076 	}
       
  1077 	
       
  1078 void CApaAppArcServSession::GetAppByDataTypeL(const RMessage2& aMessage) const
       
  1079 	{
       
  1080 	TPckgBuf<TDataType> dataType;
       
  1081 	aMessage.ReadL(0,dataType);
       
  1082 	const TUid serviceUid = { aMessage.Int1() };
       
  1083 	TUid uid;
       
  1084 	iServ.GetAppForMimeType(dataType(),serviceUid,uid);
       
  1085 	TPckgC<TUid> uidpckg(uid);
       
  1086 	aMessage.WriteL(2,uidpckg);
       
  1087 	aMessage.Complete(KErrNone);
       
  1088 	}
       
  1089 
       
  1090 void CApaAppArcServSession::GetExecutableNameGivenDocumentL(const RMessage2& aMessage)
       
  1091 	{
       
  1092 	HBufC* const name=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
       
  1093 	{TPtr name_asWritable(name->Des());
       
  1094 	aMessage.ReadL(2, name_asWritable);}
       
  1095 	HBufC8* const buffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(3)));
       
  1096 	{TPtr8 buffer_asWritable(buffer->Des());
       
  1097 	aMessage.ReadL(3, buffer_asWritable);}
       
  1098 	const TDataType dataType(iServ.RecognizeDataL(*name, *buffer).iDataType);
       
  1099 	CleanupStack::PopAndDestroy(2, name);
       
  1100 
       
  1101 	const TUid appUid(AppForDataTypeL(dataType, NULL));
       
  1102 	GetExecutableNameL(aMessage, appUid);
       
  1103 	}
       
  1104 
       
  1105 void CApaAppArcServSession::GetExecutableNameGivenDocumentPassedByFileHandleL(const RMessage2& aMessage)
       
  1106 	{
       
  1107 	RFile file;
       
  1108 	CleanupClosePushL(file);
       
  1109 	User::LeaveIfError(file.AdoptFromClient(aMessage, 2, 3));
       
  1110 	const TDataType dataType(iServ.RecognizeDataL(file, PreferredBufSize()).iDataType);
       
  1111 	CleanupStack::PopAndDestroy(&file);
       
  1112 
       
  1113 	const TUid appUid(AppForDataTypeL(dataType, NULL));
       
  1114 	GetExecutableNameL(aMessage, appUid);
       
  1115 	}
       
  1116 
       
  1117 void CApaAppArcServSession::GetExecutableNameGivenDataTypeL(const RMessage2& aMessage)
       
  1118 	{
       
  1119 	if (sizeof(TDataType) != aMessage.GetDesLengthL(2))
       
  1120 		{
       
  1121 		//Leave with KErrArgument if client passes other than TDataType
       
  1122 		User::Leave(KErrArgument);
       
  1123 		}
       
  1124 	TDataType dataType;
       
  1125 	{TPckg<TDataType> dataType_asDescriptor(dataType);
       
  1126 	aMessage.ReadL(2, dataType_asDescriptor);}
       
  1127 	const TUid appUid(AppForDataTypeL(dataType, NULL));
       
  1128 	GetExecutableNameL(aMessage, appUid);
       
  1129 	}
       
  1130 
       
  1131 void CApaAppArcServSession::GetExecutableNameGivenAppUidL(const RMessage2& aMessage)
       
  1132 	{
       
  1133 	const TUid appUid(TUid::Uid(aMessage.Int2()));
       
  1134 	GetExecutableNameL(aMessage, appUid);
       
  1135 	}
       
  1136 
       
  1137 void CApaAppArcServSession::GetExecutableNameL(const RMessage2& aMessage, TUid aAppUid)
       
  1138 	{
       
  1139 	const CApaAppData* appData=NULL;
       
  1140 	TApaAppEntry entry;
       
  1141 	if (!iAppListSession->FindAppInList(appData, entry, aAppUid))
       
  1142 		User::Leave(iAppListSession->AppList().IsFirstScanComplete() ? KErrNotFound : RApaLsSession::EAppListInvalid);
       
  1143 
       
  1144 	const TDesC& executableName(entry.iFullName);
       
  1145 	if (!executableName.Length())
       
  1146 		User::Leave(KErrNotFound);
       
  1147 
       
  1148 	aMessage.WriteL(1, executableName); // the "logical" executable name - for non-native applications this is the name of the MIDlet, Python script, etc
       
  1149 	WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(aMessage, 0, *appData);
       
  1150 	}
       
  1151 
       
  1152 void CApaAppArcServSession::GetNativeExecutableNameIfNonNativeL(const RMessage2& aMessage)
       
  1153 	{
       
  1154 	RBuf logicalExecutableName;
       
  1155 	logicalExecutableName.CreateL(User::LeaveIfError(aMessage.GetDesLength(1)));
       
  1156 	CleanupClosePushL(logicalExecutableName);
       
  1157 	aMessage.ReadL(1, logicalExecutableName);
       
  1158 	CApaAppData* const appData=iAppListSession->AppList().AppDataByFileName(logicalExecutableName);
       
  1159 	if (appData!=NULL)
       
  1160 		WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(aMessage, 0, *appData);
       
  1161 
       
  1162 	CleanupStack::PopAndDestroy(&logicalExecutableName);
       
  1163 	}
       
  1164 
       
  1165 void CApaAppArcServSession::WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(const RMessage2& aMessage, TInt aMessageSlotForNativeExecutable, const CApaAppData& aAppData)
       
  1166 	{
       
  1167 	HBufC8* opaqueData=NULL;
       
  1168 	const TPtrC8 opaqueData_asTPtrC8(aAppData.OpaqueData());
       
  1169 	const TInt lengthOfOpaqueData(opaqueData_asTPtrC8.Length());
       
  1170 	if (lengthOfOpaqueData>0)
       
  1171 		opaqueData=opaqueData_asTPtrC8.AllocLC();
       
  1172 
       
  1173 	const TUid nonNativeApplicationType(aAppData.NonNativeApplicationType());
       
  1174 	if (nonNativeApplicationType!=TUid::Null())
       
  1175 		aMessage.WriteL(aMessageSlotForNativeExecutable, iServ.NativeExecutableL(nonNativeApplicationType));
       
  1176 
       
  1177 	delete iOpaqueData_pendingDispatchToClient; // only done when the potentially leaving stuff has all succeeded
       
  1178 	iOpaqueData_pendingDispatchToClient=opaqueData; // want to do this, even if opaqueData is NULL
       
  1179 	if (opaqueData)
       
  1180 		{
       
  1181 		CleanupStack::Pop(opaqueData);
       
  1182 		aMessage.Complete(lengthOfOpaqueData);
       
  1183 		}
       
  1184 	}
       
  1185 
       
  1186 void CApaAppArcServSession::GetOpaqueDataL(const RMessage2& aMessage)
       
  1187 	{
       
  1188 	if (iOpaqueData_pendingDispatchToClient==NULL)
       
  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)
       
  1190 
       
  1191 	aMessage.WriteL(0, *iOpaqueData_pendingDispatchToClient);
       
  1192 	delete iOpaqueData_pendingDispatchToClient;
       
  1193 	iOpaqueData_pendingDispatchToClient=NULL;
       
  1194 	}
       
  1195 
       
  1196 void CApaAppListServSession::GetAppInfoL(TUid aUid, TApaAppInfo& aInfo)
       
  1197 	{
       
  1198 	const CApaAppData* app = NULL;
       
  1199 	TApaAppEntry entry;
       
  1200 	if (!FindAppInList(app, entry, aUid))
       
  1201 		User::Leave(KErrNotFound);
       
  1202 
       
  1203 	aInfo.iUid = entry.iUidType[2];
       
  1204 	aInfo.iFullName = entry.iFullName;
       
  1205 	aInfo.iCaption = app->Caption();
       
  1206 	aInfo.iShortCaption = app->ShortCaption();
       
  1207 	}
       
  1208 	
       
  1209 void CApaAppArcServSession::DoRecognizeUnpackLC(HBufC*& aName, HBufC8*& aBuffer, const RMessage2& aMessage)
       
  1210 	{
       
  1211 	ASSERT(aName==NULL);
       
  1212 	ASSERT(aBuffer==NULL);
       
  1213 	aName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
       
  1214 	TPtr name(aName->Des());
       
  1215 	aMessage.ReadL(1, name);
       
  1216 	aBuffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
       
  1217 	TPtr8 buffer(aBuffer->Des());
       
  1218 	aMessage.ReadL(2, buffer);
       
  1219 	}
       
  1220 
       
  1221 void CApaAppArcServSession::RecognizeDataL(const RMessage2& aMessage)
       
  1222 // Recognize the data type of an object
       
  1223 	{
       
  1224 	HBufC* name=NULL;
       
  1225 	HBufC8* buffer=NULL;
       
  1226 	DoRecognizeUnpackLC(name,buffer,aMessage);
       
  1227 
       
  1228 	const TDataRecognitionResult result = iServ.RecognizeDataL(*name, *buffer);
       
  1229 
       
  1230 	CleanupStack::PopAndDestroy(2); // name & buffer
       
  1231 	aMessage.WriteL(0,TPckgC<TDataRecognitionResult>(result));
       
  1232 	}
       
  1233 
       
  1234 
       
  1235 void CApaAppArcServSession::RecognizeFilesL(const RMessage2& aMessage)
       
  1236 	{
       
  1237 	// if there is an outstanding async. request, we even don't allow 
       
  1238 	// a synchronous request at the same time (due to the two required
       
  1239 	// server messages)
       
  1240 	if (iAsyncRecognitionActive)
       
  1241 		User::Leave(KErrInUse);
       
  1242 
       
  1243 	_LIT8(KAllDataTypes,"*");
       
  1244 
       
  1245 	// retrieve pathname
       
  1246 	HBufC* const path=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
       
  1247 	TPtr pathPtr(path->Des());
       
  1248 	aMessage.ReadL(0,pathPtr);
       
  1249 
       
  1250 	// retrieve data type filter
       
  1251 	HBufC8* const dataType = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
       
  1252 	TPtr8 dataTypePtr(dataType->Des());
       
  1253 	aMessage.ReadL(2,dataTypePtr);
       
  1254 
       
  1255 	delete iRecognitionResult;
       
  1256 	iRecognitionResult = NULL;
       
  1257 
       
  1258 	if(dataType->Compare(KAllDataTypes) == 0)
       
  1259 		{
       
  1260 		iRecognitionResult = new (ELeave) CDirectoryRecognitionResult(path, NULL);
       
  1261 		CleanupStack::PopAndDestroy(dataType);
       
  1262 		}
       
  1263 	else
       
  1264 		{
       
  1265 		iRecognitionResult = new (ELeave) CDirectoryRecognitionResult(path,dataType);	
       
  1266 		CleanupStack::Pop(dataType);
       
  1267 		}
       
  1268 
       
  1269 	CleanupStack::Pop(path);		// ownership transferred to CDirectoryRecognitionResult
       
  1270 	ASSERT(iFileRecognitionUtility);
       
  1271 	iFileRecognitionUtility->RecognizeSynchronouslyL(*iRecognitionResult);
       
  1272 	aMessage.WriteL(1,TPckgBuf<TUint>(iRecognitionResult->RequiredBufferSize()));
       
  1273 	}
       
  1274 
       
  1275 void CApaAppArcServSession::TransferRecognitionResultL(const RMessage2& aMessage)
       
  1276 	{
       
  1277 	if(iRecognitionResult == NULL)
       
  1278 		User::Leave(KErrNotReady);
       
  1279 
       
  1280 	iAsyncRecognitionActive = EFalse;
       
  1281 
       
  1282 	// if data is too big for buffer, tell client
       
  1283 	const TInt sizeOfBuffer=aMessage.Int2();	
       
  1284 	if(sizeOfBuffer < iRecognitionResult->RequiredBufferSize())
       
  1285 		User::Leave(KErrTooBig);
       
  1286 
       
  1287 	// buffer is big enough -> write result to buffer
       
  1288 	CBufFlat* const buf=CBufFlat::NewL(iRecognitionResult->RequiredBufferSize());
       
  1289 	CleanupStack::PushL(buf);
       
  1290 	buf->ExpandL(0,iRecognitionResult->RequiredBufferSize());
       
  1291 
       
  1292 	RBufWriteStream writeStream;
       
  1293 	writeStream.Open(*buf);
       
  1294 	iRecognitionResult->WriteToStreamL(writeStream);
       
  1295 	aMessage.WriteL(1,buf->Ptr(0));
       
  1296 
       
  1297 	delete iRecognitionResult;
       
  1298 	iRecognitionResult = NULL;
       
  1299 
       
  1300 	CleanupStack::PopAndDestroy(buf);
       
  1301 	}
       
  1302 
       
  1303 void CApaAppArcServSession::RecognizeFilesAsyncL(const RMessage2& aMessage)
       
  1304 	{
       
  1305 	if (iAsyncRecognitionActive)
       
  1306 		User::Leave(KErrInUse);
       
  1307 	else
       
  1308 		{
       
  1309 		_LIT8(KAllDataTypes,"*");
       
  1310 
       
  1311 		HBufC* path = HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
       
  1312 		TPtr pathPtr(path->Des());
       
  1313 		aMessage.ReadL(0,pathPtr);
       
  1314 
       
  1315 		// retrieve data type filter
       
  1316 		HBufC8* dataType = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
       
  1317 		TPtr8 dataTypePtr(dataType->Des());
       
  1318 		aMessage.ReadL(2,dataTypePtr);
       
  1319 
       
  1320 		delete iRecognitionResult;
       
  1321 		iRecognitionResult = NULL;
       
  1322 
       
  1323 		if(dataType->Compare(KAllDataTypes) == 0)
       
  1324 			{
       
  1325 			iRecognitionResult = new (ELeave) CDirectoryRecognitionResult(path,NULL);
       
  1326 			CleanupStack::PopAndDestroy(dataType);
       
  1327 			}
       
  1328 		else
       
  1329 			{
       
  1330 			iRecognitionResult = new (ELeave) CDirectoryRecognitionResult(path,dataType);
       
  1331 			CleanupStack::Pop(dataType);
       
  1332 			}
       
  1333 
       
  1334 		CleanupStack::Pop(path);	// ownership transferred to CDirectoryRecognitionResult
       
  1335 		ASSERT(iFileRecognitionUtility);
       
  1336 		iFileRecognitionUtility->RecognizeAsynchronously(*iRecognitionResult,aMessage);
       
  1337 		iAsyncRecognitionActive = ETrue;
       
  1338 		}
       
  1339 	}
       
  1340 
       
  1341 /** The function interrogates all available rule based plug-ins if apparc can launch application with 
       
  1342 given full name. It loops through all plug-ins until gets value different from 
       
  1343 CAppLaunchChecker::EAppLaunchIndifferent. 
       
  1344 The application will be launched if the return code is not equal to
       
  1345 CAppLaunchChecker::EAppLaunchDecline 
       
  1346 */
       
  1347 void CApaAppArcServSession::AquirePermissionToLaunchAppL(const RMessage2& aMessage) const
       
  1348 	{
       
  1349 	const CApaScanningRuleBasedPlugIns* theRuleBasedPlugIns = iServ.RuleBasedPlugIns();
       
  1350 	const TInt theNumImp = (theRuleBasedPlugIns ? theRuleBasedPlugIns->ImplementationCount() : 0);
       
  1351 	if(!theNumImp || !iServ.WsSession().Handle())
       
  1352 		{
       
  1353 		// Proceed with launch if rule based plug-in framework was not initialized
       
  1354 		aMessage.Complete(ETrue);
       
  1355 		return;
       
  1356 		}
       
  1357 
       
  1358 	// Get the name of the app to start from the IPC message object
       
  1359 	HBufC* theFullFileName = HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
       
  1360 	TPtr theFullFileNamePtr(theFullFileName->Des());
       
  1361 	aMessage.ReadL(0, theFullFileNamePtr);
       
  1362 	
       
  1363 	// Ge the application's UID from its name
       
  1364 	const TUid theUid = iAppListSession->AppUidFromFullFileNameL(theFullFileNamePtr);
       
  1365 	CleanupStack::PopAndDestroy(theFullFileName); 
       
  1366 
       
  1367 	// Iterate through all plug-ins and look for one that's not indifferent
       
  1368 	CAppLaunchChecker::TAppLaunchCode theLaunchCode = CAppLaunchChecker::EAppLaunchIndifferent;	
       
  1369 	TApaTaskList theTaskList(iServ.WsSession());
       
  1370 	for(TInt ii = 0; ii < theNumImp; ii++)
       
  1371 		{
       
  1372 		CAppLaunchChecker* const theLauncherChecker = (*theRuleBasedPlugIns)[ii];
       
  1373 		TRAP_IGNORE(theLaunchCode = theLauncherChecker->OkayToLaunchL(theUid, theTaskList));
       
  1374 		if(theLaunchCode != CAppLaunchChecker::EAppLaunchIndifferent)
       
  1375 			break;
       
  1376 		}
       
  1377 		
       
  1378 	// Return the result
       
  1379 	const TBool okayToLaunch = (theLaunchCode != CAppLaunchChecker::EAppLaunchDecline);
       
  1380 	aMessage.Complete(okayToLaunch);
       
  1381 	}
       
  1382 
       
  1383 /** 
       
  1384 @param aFullFileName This filename is parsed and the path is replaced with "\\sys\\bin\\". 
       
  1385 		It uses ".exe" if no other is provided in the filename passed.  If drive name is 
       
  1386 		present in the filename then it scans through the \\sys\\bin of that particular drive,
       
  1387 		otherwise it scans through the \\sys\\bin folders in all the avaliable drives.
       
  1388 @return Returns the Application Uid for the aFullFileName application.
       
  1389 */
       
  1390 TUid CApaAppListServSession::AppUidFromFullFileNameL(const TDesC& aFullFileName) const
       
  1391 	{
       
  1392 	
       
  1393 	// If the appliation still wasn't found, use AppArc's appliation list
       
  1394 	// Since we cannot get the Uid of NonNative apps by passing filename to RFs::Entry
       
  1395 	CApaAppData* appData = iAppList.AppDataByFileName(aFullFileName);
       
  1396 	if (appData)
       
  1397 		{
       
  1398 		TApaAppEntry appEntry = appData->AppEntry();
       
  1399 		return appEntry.iUidType[2];
       
  1400 		}
       
  1401 	
       
  1402 	
       
  1403 //mm: Why does this code not use AppArc's application list only?	
       
  1404 //mm: The order in which different methods to locate the app is used seems inefficient.
       
  1405 	_LIT(KSysBin, "\\sys\\bin\\");
       
  1406 	_LIT(KFileExtension, ".EXE");
       
  1407 	
       
  1408 	RLoader loader;
       
  1409 	User::LeaveIfError(loader.Connect());
       
  1410 	CleanupClosePushL(loader);
       
  1411 	TPckgBuf<RLibrary::TInfo> dllInfo;
       
  1412 
       
  1413 	TParse parse;
       
  1414 	parse.Set(aFullFileName,NULL,NULL);
       
  1415 
       
  1416 	// If the drive letter has been specified, look on that drive only...
       
  1417 	TInt error = KErrNotFound;
       
  1418 	if (parse.DrivePresent())
       
  1419 		{
       
  1420 		const TPtrC appDrive = parse.Drive();
       
  1421 		TBuf<KMaxFileName>fileName(appDrive);
       
  1422 		fileName.Append(KSysBin);
       
  1423 		User::LeaveIfError(parse.SetNoWild(fileName, &aFullFileName, &KFileExtension));
       
  1424 		error = loader.GetInfo(parse.FullName(), dllInfo);
       
  1425 		}
       
  1426 	else	// ...otherwise scan all drives.
       
  1427 		{
       
  1428 		User::LeaveIfError(parse.SetNoWild(KSysBin, &aFullFileName, &KFileExtension)); 
       
  1429 		TFileName tempFileName(parse.FullName());
       
  1430 		TDriveList driveList;
       
  1431 		User::LeaveIfError(iFs.DriveList(driveList));
       
  1432 		for (TInt driveNumber = EDriveY; driveNumber != KFinishedScanning; driveNumber = NextDriveToScan(driveNumber))
       
  1433 			{
       
  1434 			if (driveList[driveNumber]!=0)
       
  1435 				{
       
  1436 				User::LeaveIfError(parse.SetNoWild(TDriveUnit(driveNumber).Name(), &tempFileName, NULL));
       
  1437 				error = loader.GetInfo(parse.FullName(), dllInfo);
       
  1438 				if (error == KErrNone)
       
  1439 					break;
       
  1440 				}
       
  1441 			}
       
  1442 		}
       
  1443 
       
  1444 	CleanupStack::PopAndDestroy(&loader);
       
  1445 	// Return the UID if found and no errors occured
       
  1446 	if(!error)
       
  1447 		return dllInfo().iUids[2];
       
  1448 	
       
  1449 	// If the application wasn't found
       
  1450 	// Try looking for the application using normal F32. This won't work in protected directories
       
  1451 
       
  1452 	// Since we can't use RFs::Entry if the path refers the protected system directory (i.e. \sys\bin)...
       
  1453 	User::LeaveIfError(parse.SetNoWild(aFullFileName, NULL, NULL));
       
  1454 	if(parse.Path().FindF(KSysBin) == 0)
       
  1455 		User::Leave(KErrNotFound);	// ... then return not-found.
       
  1456 
       
  1457 //mm: Surely we should still be allowed to use AppArc below?
       
  1458 
       
  1459 	// The following is valid for non-native applications only
       
  1460 	TEntry entry;
       
  1461 	error = iFs.Entry(aFullFileName, entry);
       
  1462 	if(!error)
       
  1463 		return entry.iType[2];
       
  1464 
       
  1465 	User::Leave(KErrNotFound);
       
  1466 	return TUid::Null();	// Won't be called
       
  1467 	}
       
  1468 
       
  1469 /**
       
  1470 Applies the scanning order Y: through A: then Z: last.
       
  1471 */
       
  1472 TInt CApaAppListServSession::NextDriveToScan(TInt aCurrentDrive)
       
  1473 	{
       
  1474 	if (aCurrentDrive == EDriveZ)
       
  1475 		return KFinishedScanning;
       
  1476 	else if (aCurrentDrive == 0)
       
  1477 		return EDriveZ; 	// finally scan the last one
       
  1478 	else if (aCurrentDrive > 0 && aCurrentDrive < KMaxDrives)
       
  1479 		return aCurrentDrive - 1;
       
  1480 	else
       
  1481 		return KErrGeneral; // never gets here, but it wont compile otherwise
       
  1482 	}
       
  1483 
       
  1484 void CApaAppArcServSession::CancelRecognizeFiles()
       
  1485 	{
       
  1486 	if (iAsyncRecognitionActive)
       
  1487 		{
       
  1488 		ASSERT(iFileRecognitionUtility);
       
  1489 		iFileRecognitionUtility->CancelRecognitionRequest();
       
  1490 		iAsyncRecognitionActive = EFalse;
       
  1491 		}
       
  1492 	}
       
  1493 
       
  1494 void CApaAppArcServSession::RecognizeDataPassedByFileHandleL(const RMessage2& aMessage)
       
  1495 // Recognize the data type of an object
       
  1496 	{
       
  1497 	RFile file;
       
  1498 	CleanupClosePushL(file);
       
  1499 	User::LeaveIfError(file.AdoptFromClient(aMessage, 1, 2));
       
  1500 	const TDataRecognitionResult result(iServ.RecognizeDataL(file, PreferredBufSize()));
       
  1501 	CleanupStack::PopAndDestroy(&file);
       
  1502 	aMessage.WriteL(0, TPckgC<TDataRecognitionResult>(result));
       
  1503 	}
       
  1504 	
       
  1505 void CApaAppArcServSession::RecognizeSpecificDataL(const RMessage2& aMessage)
       
  1506 // Determine whether an object is of a specific data type
       
  1507 	{
       
  1508 	HBufC* name=NULL;
       
  1509 	HBufC8* buffer=NULL;
       
  1510 	DoRecognizeUnpackLC(name,buffer,aMessage);
       
  1511 	TDataType dataType;
       
  1512 	{TPckg<TDataType> dataType_asDescriptor(dataType);
       
  1513 	aMessage.ReadL(0, dataType_asDescriptor);}
       
  1514 	aMessage.Complete(iServ.RecognizeDataL(*name,*buffer,dataType));
       
  1515 	CleanupStack::PopAndDestroy(2); // name & buffer
       
  1516 	}
       
  1517 
       
  1518 void CApaAppArcServSession::RecognizeSpecificDataPassedByFileHandleL(const RMessage2& aMessage)
       
  1519 	{
       
  1520 	RFile file;
       
  1521 	CleanupClosePushL(file);
       
  1522 	User::LeaveIfError(file.AdoptFromClient(aMessage, 1, 2));
       
  1523 	TDataType dataType;
       
  1524 	{TPckg<TDataType> dataType_asDescriptor(dataType);
       
  1525 	aMessage.ReadL(0,dataType_asDescriptor);}
       
  1526 	aMessage.Complete(iServ.RecognizeDataL(file, PreferredBufSize(), dataType));
       
  1527 	CleanupStack::PopAndDestroy(&file);
       
  1528 	}
       
  1529 
       
  1530 void CApaAppListServSession::InitListL(const RMessage2& aMessage, TAppListType aType)
       
  1531 // carries out initialisation prior to starting to pass a new list across
       
  1532 	{
       
  1533 	iAppListType = aType;
       
  1534 	iAppListScreenMode = aMessage.Int0();
       
  1535 	if (aType == EListFilteredEmbeddedApps)
       
  1536 		{
       
  1537 		TApaEmbeddabilityFilter filter;
       
  1538 		{TPckg<TApaEmbeddabilityFilter> filter_asDescriptor(filter);
       
  1539 		aMessage.ReadL(1,filter_asDescriptor);}
       
  1540 		iEmbeddabilityFilter = filter;
       
  1541 		}
       
  1542 
       
  1543 	if (aType == EListCapabilityAttrFilteredApps)
       
  1544 		{
       
  1545 		iCapabilityAttrFilterMask = aMessage.Int1();
       
  1546 		iCapabilityAttrFilterValue = aMessage.Int2();
       
  1547 		}
       
  1548 
       
  1549 	if (aType == EListServerApps)
       
  1550 		iServiceUid = TUid::Uid(aMessage.Int1());
       
  1551 
       
  1552 	iApaAppInfoArray.ResetAndDestroy();
       
  1553 	iFlags|=EAppListPopulationPending;
       
  1554 	}
       
  1555 
       
  1556 void CApaAppListServSession::EmbedCount(const RMessage2& aMessage) const
       
  1557 // writes back the number of embedded apps in the list
       
  1558 	{
       
  1559 	TInt count=0;
       
  1560 	const CApaAppList& list = iAppList;
       
  1561 	CApaAppData* app = list.FirstApp();
       
  1562 	TApaEmbeddabilityFilter filter;
       
  1563 	filter.AddEmbeddability(TApaAppCapability::EEmbeddable);
       
  1564 	filter.AddEmbeddability(TApaAppCapability::EEmbeddableOnly);
       
  1565 	while (app)
       
  1566 		{
       
  1567 		if (!AppIsControlPanelItem(*app) && AppMatchesEmbeddabilityFilter(*app, filter))
       
  1568 			count++;
       
  1569 
       
  1570 		app = list.NextApp(app);
       
  1571 		}
       
  1572 
       
  1573 	aMessage.Complete(count);
       
  1574 	}
       
  1575 
       
  1576 void CApaAppListServSession::AppCount(const RMessage2& aMessage) const
       
  1577 // writes back the number of apps in the list
       
  1578 	{
       
  1579 	TInt count = 0;
       
  1580 	const CApaAppList& list = iAppList;
       
  1581 	CApaAppData* app = list.FirstApp();
       
  1582 	while (app)
       
  1583 		{
       
  1584 		if (!AppIsControlPanelItem(*app))
       
  1585 			count++;
       
  1586 
       
  1587 		app = list.NextApp(app);
       
  1588 		}
       
  1589 
       
  1590 	aMessage.Complete(count);
       
  1591 	}
       
  1592 
       
  1593 void CApaAppListServSession::GetNextAppL(const RMessage2& aMessage)
       
  1594 	{
       
  1595 	if (iFlags&EAppListPopulationPending)
       
  1596 		{
       
  1597 		const CApaAppList& list=iAppList;
       
  1598 		if (!(list.IsFirstScanComplete()))
       
  1599 			User::Leave(KErrCorrupt);
       
  1600 		
       
  1601 		iApaAppInfoArray.ResetAndDestroy();
       
  1602 		for (CApaAppData* appData = list.FirstApp(iAppListScreenMode); appData != NULL; appData = list.NextApp(appData, iAppListScreenMode))
       
  1603 			{
       
  1604 			if (iAppListType==EListFilteredEmbeddedApps && (AppIsControlPanelItem(*appData) || !AppMatchesEmbeddabilityFilter(*appData, iEmbeddabilityFilter)))
       
  1605 				continue;
       
  1606 
       
  1607 			if (iAppListType==EListCapabilityAttrFilteredApps && !AppMatchesCapabilityAttrFilter(*appData))
       
  1608 				continue;
       
  1609 
       
  1610 			if (iAppListType==EListServerApps && !appData->ImplementsService(iServiceUid))
       
  1611 				continue;
       
  1612 
       
  1613 			CApaAppInfo* apaAppInfo= new (ELeave)CApaAppInfo();
       
  1614 			CleanupStack::PushL(apaAppInfo);
       
  1615 			apaAppInfo->SetCaptionL(appData->Caption());
       
  1616 			apaAppInfo->SetShortCaptionL(appData->ShortCaption());
       
  1617 			apaAppInfo->SetFullNameL(appData->AppEntry().iFullName);
       
  1618 			apaAppInfo->SetUid(appData->AppEntry().iUidType[2]);
       
  1619 			User::LeaveIfError(iApaAppInfoArray.Append(apaAppInfo));
       
  1620 			CleanupStack::Pop(apaAppInfo);
       
  1621 			}
       
  1622 		
       
  1623 		iFlags &= ~EAppListPopulationPending;
       
  1624 		}
       
  1625 
       
  1626 	if (!iApaAppInfoArray.Count())
       
  1627 		User::Leave(KErrNotFound);
       
  1628 
       
  1629 	TApaAppInfo* info=new(ELeave)TApaAppInfo; 
       
  1630 	CleanupStack::PushL(info);
       
  1631 	CApaAppInfo* apaAppInfo = iApaAppInfoArray[0];
       
  1632 	info->iUid = apaAppInfo->Uid();
       
  1633 	info->iFullName = apaAppInfo->FullName();
       
  1634 	info->iCaption = apaAppInfo->Caption();
       
  1635 	// Get the length of the target descriptor
       
  1636 	TInt targetLen=aMessage.GetDesMaxLength(1);
       
  1637 	if (targetLen==KApaAppInfoDesMaxLength)
       
  1638 		info->iShortCaption = apaAppInfo->ShortCaption();
       
  1639 
       
  1640 	iApaAppInfoArray.Remove(0);
       
  1641 	delete apaAppInfo;
       
  1642 	TPckgC<TApaAppInfo> infoPk(*info);
       
  1643 	if (targetLen<KApaAppInfoDesMaxLength)
       
  1644 		infoPk.Set(infoPk.Left(_FOFF(TApaAppInfo,iShortCaption))); // reduce the length of infoPk to the 7.0 size of TApaAppInfo
       
  1645 
       
  1646 	aMessage.WriteL(1,infoPk);
       
  1647 	CleanupStack::PopAndDestroy(info);
       
  1648 	}
       
  1649 
       
  1650 TBool CApaAppListServSession::AppMatchesEmbeddabilityFilter(const CApaAppData& aAppData, const TApaEmbeddabilityFilter& aEmbeddabilityFilter) const
       
  1651 // returns True if aAppData's embeddability matches the filter set by InitListL
       
  1652 	{
       
  1653 	TApaAppCapabilityBuf capabilityBuf;
       
  1654 	aAppData.Capability(capabilityBuf);
       
  1655 
       
  1656 	return (aEmbeddabilityFilter.MatchesEmbeddability(capabilityBuf().iEmbeddability));
       
  1657 	}
       
  1658 
       
  1659 TBool CApaAppListServSession::AppMatchesCapabilityAttrFilter(const CApaAppData& aAppData) const
       
  1660 // returns True if aAppData's capability attributes match the filter set by InitListL
       
  1661 	{
       
  1662 	TApaAppCapabilityBuf capabilityBuf;
       
  1663 	aAppData.Capability(capabilityBuf);
       
  1664 	return ((capabilityBuf().iAttributes & iCapabilityAttrFilterMask) == (iCapabilityAttrFilterValue & iCapabilityAttrFilterMask));
       
  1665 	}
       
  1666 
       
  1667 TBool CApaAppListServSession::AppIsControlPanelItem(const CApaAppData& aAppData)
       
  1668 // returns True if aAppData represents a control panel app
       
  1669 	{
       
  1670 	TApaAppCapabilityBuf capabilityBuf;
       
  1671 	aAppData.Capability(capabilityBuf);
       
  1672 	return (capabilityBuf().iAttributes & TApaAppCapability::EControlPanelItem);
       
  1673 	}
       
  1674 
       
  1675 /**
       
  1676 locate app in list, return EFalse if it isn't present
       
  1677 search is regardless of screen mode.
       
  1678 @internalComponent
       
  1679 */
       
  1680 TBool CApaAppListServSession::FindAppInList(CApaAppData*& aApp, TApaAppEntry& aEntry, TUid aAppUid)
       
  1681 	{
       
  1682 	// Look for the app with aAppUid in the app list we keep
       
  1683 	const CApaAppList& list = iAppList;
       
  1684 	aApp = list.AppDataByUid(aAppUid);
       
  1685 	if (aApp)
       
  1686 		aEntry = aApp->AppEntry();
       
  1687 	
       
  1688 	// If the app list is currently in flux, try to nail down the app by looking for it specifically
       
  1689 	const TBool appPendingOnLangChange = (aApp && list.IsLanguageChangePending() && aApp->IsPending());	
       
  1690 	if ((!aApp || appPendingOnLangChange) && !list.IsIdleUpdateComplete())
       
  1691 		{
       
  1692 		// 1. App wasn't found, but an app scan is currently in progress,
       
  1693 		// so try to find and add the specific app we're looking for to the list
       
  1694 		
       
  1695 		// 2. On language change event, current app scan could not yet update the found app, 
       
  1696 		// so try to update the specific app we're looking for, in the list.
       
  1697 		if(aAppUid != KNullUid)
       
  1698 			{
       
  1699 			CApaAppData* app = NULL;
       
  1700 			TRAPD(err, app = FindSpecificAppL(aAppUid));
       
  1701 			if (!err && app)
       
  1702 				{
       
  1703 				// app has been found and added to the app list
       
  1704 				aApp = app;
       
  1705 				aEntry = aApp->AppEntry();
       
  1706 				}
       
  1707  			}
       
  1708  		}
       
  1709 
       
  1710 	return (aApp != NULL);
       
  1711 	}
       
  1712 
       
  1713 CApaAppData* CApaAppListServSession::FindSpecificAppL(TUid aAppUid)
       
  1714 	{
       
  1715 	//Scans the drives and folder lists for the specific app
       
  1716 	CApaAppRegFinder* regFinder = CApaAppRegFinder::NewLC(iFs);
       
  1717 	CApaAppData* app = iAppList.FindAndAddSpecificAppL(regFinder, aAppUid);
       
  1718 	CleanupStack::PopAndDestroy(regFinder);
       
  1719 	return app;
       
  1720 	}
       
  1721 
       
  1722 void CApaAppListServSession::GetAppInfoL(const RMessage2& aMessage)
       
  1723 	{
       
  1724 	// get UID of required app
       
  1725 	const TUid uid = TUid::Uid(aMessage.Int0());
       
  1726 	TApaAppInfo* info = new(ELeave) TApaAppInfo; // on heap to avoid running out of stack
       
  1727 	CleanupStack::PushL(info);
       
  1728 	GetAppInfoL(uid, *info);
       
  1729 	TPckgC<TApaAppInfo> infoPk(*info);	
       
  1730 	aMessage.WriteL(1, infoPk);
       
  1731 	CleanupStack::PopAndDestroy(info);
       
  1732 	}
       
  1733 
       
  1734 void CApaAppListServSession::GetAppCapabilityL(const RMessage2& aMessage)
       
  1735 	{	  								  
       
  1736 	const TUid uid = TUid::Uid(aMessage.Int1());
       
  1737 	const CApaAppData& app = FindAppInListL(uid);
       
  1738 
       
  1739 	TInt targetLen = aMessage.GetDesMaxLength(0);
       
  1740 	HBufC8* buf = HBufC8::NewLC(User::LeaveIfError(targetLen));
       
  1741 	TPtr8 ptr = buf->Des();
       
  1742 	app.Capability(ptr);
       
  1743 	ptr.SetLength(targetLen);
       
  1744 	aMessage.WriteL(0, *buf);
       
  1745 	CleanupStack::PopAndDestroy(buf); 
       
  1746 	}
       
  1747 
       
  1748 void CApaAppListServSession::GetDefaultScreenNumberL(const RMessage2& aMessage)
       
  1749 	{
       
  1750 	const TUid uid=TUid::Uid(aMessage.Int0());
       
  1751 	const CApaAppData& app = FindAppInListL(uid);
       
  1752 
       
  1753 	aMessage.Complete(app.DefaultScreenNumber());
       
  1754 	}
       
  1755 
       
  1756 
       
  1757 void CApaAppListServSession::SetNotify(const RMessage2& aMessage)
       
  1758 	{
       
  1759 	if (!iNotifyMessage.IsNull())
       
  1760 		aMessage.Panic(KApaPanicCli,ENotifierAlreadyPresent);
       
  1761 	else
       
  1762 		{
       
  1763 		const TBool completeImmediatelyIfNoScanImpendingOrInProgress=aMessage.Int0();
       
  1764 		if ((!completeImmediatelyIfNoScanImpendingOrInProgress) ||
       
  1765 			iAppArcSrv.AppFsMonitor().AnyNotificationImpending() ||
       
  1766 			iAppList.AppScanInProgress())
       
  1767 			iNotifyMessage=aMessage;
       
  1768 		else
       
  1769 			aMessage.Complete(KErrNone);
       
  1770 		}
       
  1771 	}
       
  1772 
       
  1773 void CApaAppArcServSession::NotifyClients(TInt aReason)
       
  1774 	{
       
  1775 	iAppListSession->NotifyClients(aReason);
       
  1776 	}
       
  1777 
       
  1778 void CApaAppListServSession::CancelNotify()
       
  1779 	{
       
  1780 	NotifyClients(KErrCancel);
       
  1781 	}
       
  1782 
       
  1783 void CApaAppListServSession::NotifyClients(TInt aReason)
       
  1784 	{
       
  1785 	if (!iNotifyMessage.IsNull())
       
  1786 		iNotifyMessage.Complete(aReason);
       
  1787 	
       
  1788 	//Notify client for scan complete.
       
  1789 	NotifyScanComplete();
       
  1790 	}
       
  1791 
       
  1792 void CApaAppListServSession::AppInfoProvidedByRegistrationFileL(const RMessage2& aMessage)
       
  1793 	{
       
  1794 	// get UID of required app
       
  1795 	const TUid uid = TUid::Uid(aMessage.Int0());
       
  1796 
       
  1797 	// locate app in list
       
  1798 	const CApaAppData& app = FindAppInListL(uid);
       
  1799 	
       
  1800 	const TBool registrationFileUsed = app.RegistrationFileUsed();
       
  1801 	TPckgC<TBool> pckg(registrationFileUsed);
       
  1802 	aMessage.WriteL(1, pckg);
       
  1803 	}
       
  1804 
       
  1805 void CApaAppListServSession::IconFileNameL(const RMessage2& aMessage)
       
  1806 	{
       
  1807 	// get UID of required app
       
  1808 	const TUid uid=TUid::Uid(aMessage.Int0());
       
  1809 
       
  1810 	// locate app in list
       
  1811 	const CApaAppData& app = FindAppInListL(uid);
       
  1812 
       
  1813 	if (!app.RegistrationFileUsed())
       
  1814 		User::Leave(KErrNotSupported);
       
  1815 	else
       
  1816 		{
       
  1817 		TPtrC iconFileName(app.IconFileName());
       
  1818 		if (iconFileName.Length() == 0)
       
  1819 			User::Leave(KErrNotFound);
       
  1820 		else
       
  1821 			{
       
  1822 			TFileName fileName = iconFileName;
       
  1823 			TPckgC<TFileName> pckg(fileName);
       
  1824 			aMessage.WriteL(1, pckg);
       
  1825 			}
       
  1826 		}
       
  1827 	}
       
  1828 
       
  1829 void CApaAppListServSession::ViewIconFileNameL(const RMessage2& aMessage)
       
  1830 	{
       
  1831 	// get UID of required app
       
  1832 	const TUid uid=TUid::Uid(aMessage.Int0());
       
  1833 	// get UID of required view
       
  1834 	const TUid viewUid=TUid::Uid(aMessage.Int1());
       
  1835 
       
  1836 	TPtrC viewIconFileName;
       
  1837 
       
  1838 	// locate app in list
       
  1839 	const CApaAppData& app = FindAppInListL(uid);
       
  1840 
       
  1841 	if (!app.RegistrationFileUsed())
       
  1842 		User::Leave(KErrNotSupported);
       
  1843 	else
       
  1844 		{
       
  1845 		const CArrayPtr<CApaAppViewData>& viewDataArray = *app.Views();
       
  1846 		const TInt count = viewDataArray.Count();
       
  1847 		for (TInt ii=0; ii<count; ii++)
       
  1848 			{
       
  1849 			const CApaAppViewData& appViewData = *viewDataArray[ii];
       
  1850 			if (appViewData.Uid() == viewUid)
       
  1851 				{
       
  1852 				viewIconFileName.Set(appViewData.IconFileName());
       
  1853 				break;
       
  1854 				}
       
  1855 			}
       
  1856 
       
  1857 		if (viewIconFileName.Length() == 0)
       
  1858 			User::Leave(KErrNotFound);
       
  1859 		else
       
  1860 			{
       
  1861 			TFileName fileName = viewIconFileName;
       
  1862 			TPckgC<TFileName> pckg(fileName);
       
  1863 			aMessage.WriteL(2, pckg);
       
  1864 			}
       
  1865 		}
       
  1866 	}
       
  1867 
       
  1868 void CApaAppArcServSession::GetAppServicesL(const RMessage2& aMessage)
       
  1869 	{
       
  1870 	const TInt initialBufSize = aMessage.Int2();
       
  1871 	if (initialBufSize)
       
  1872 		{
       
  1873 		delete iBuffer;
       
  1874 		iBuffer = NULL;
       
  1875 		iBuffer = GetServiceBufferL(aMessage);
       
  1876 		if (iBuffer->Size() > initialBufSize)
       
  1877 			User::Leave(iBuffer->Ptr(0).Size());	// default buffer provided by client is too small, ask client to provide buffer of correct size
       
  1878 		}
       
  1879 	__ASSERT_ALWAYS(iBuffer, aMessage.Panic(KApaPanicCli,EClientBadRequest));
       
  1880 	aMessage.WriteL(3, iBuffer->Ptr(0));
       
  1881 	delete iBuffer;
       
  1882 	iBuffer = NULL;
       
  1883 	}
       
  1884 
       
  1885 CBufBase* CApaAppArcServSession::GetServiceBufferL(const RMessage2& aMessage) const
       
  1886 	{
       
  1887 	CBufBase* buffer = NULL;
       
  1888 	const TUid uid = TUid::Uid(aMessage.Int0());
       
  1889 	switch (aMessage.Function())
       
  1890 		{
       
  1891 	case EAppListServGetAppServices:
       
  1892 		buffer = iAppListSession->AppList().ServiceArrayBufferL(uid);
       
  1893 		break;
       
  1894 	case EAppListServGetServiceImplementations:
       
  1895 		buffer = iAppListSession->AppList().ServiceImplArrayBufferL(uid);
       
  1896 		break;
       
  1897 	case EAppListServGetServiceImplementationsDataType:
       
  1898 		{
       
  1899 		TDataType dataType;
       
  1900 		TPckg<TDataType> dataType_asDescriptor(dataType);
       
  1901 		aMessage.ReadL(1,dataType_asDescriptor);
       
  1902 		buffer = iAppListSession->AppList().ServiceImplArrayBufferL(uid, dataType);
       
  1903 		}
       
  1904 		break;
       
  1905 	case EAppListServGetAppServiceUids:
       
  1906 		buffer = iAppListSession->AppList().ServiceUidBufferL(uid);
       
  1907 		break;
       
  1908 	case EAppListServGetAppServiceOpaqueData:
       
  1909 		buffer = iAppListSession->AppList().ServiceOpaqueDataBufferL(uid, TUid::Uid(aMessage.Int1()));
       
  1910 		break;
       
  1911 	default:
       
  1912 		aMessage.Panic(KApaPanicCli,EClientBadRequest);
       
  1913 		User::Leave(KErrNotSupported);
       
  1914 		break;
       
  1915 		}
       
  1916 
       
  1917 	return buffer;
       
  1918 	}
       
  1919 
       
  1920 CApaAppListServSession::CApaAppInfo::CApaAppInfo()
       
  1921 	:iUid(KNullUid), iCaption(NULL), iShortCaption(NULL), iFullName(NULL)
       
  1922 	{
       
  1923 	}
       
  1924 
       
  1925 CApaAppListServSession::CApaAppInfo::~CApaAppInfo()
       
  1926 	{
       
  1927 	delete iCaption;
       
  1928 	delete iShortCaption;
       
  1929 	delete iFullName;
       
  1930 	}
       
  1931 
       
  1932 void CApaAppListServSession::CApaAppInfo::SetUid(const TUid aUid)
       
  1933 	{
       
  1934 	iUid=aUid;
       
  1935 	}
       
  1936 
       
  1937 void CApaAppListServSession::CApaAppInfo::SetCaptionL(const TDesC& aCaption)
       
  1938 	{
       
  1939 	HBufC* caption = aCaption.AllocL();
       
  1940 	delete iCaption;
       
  1941 	iCaption = caption;
       
  1942 	}
       
  1943 
       
  1944 void CApaAppListServSession::CApaAppInfo::SetShortCaptionL(const TDesC& aShortCaption)
       
  1945 	{
       
  1946 	HBufC* shortCaption = aShortCaption.AllocL();
       
  1947 	delete iShortCaption;
       
  1948 	iShortCaption = shortCaption;
       
  1949 	}
       
  1950 
       
  1951 void CApaAppListServSession::CApaAppInfo::SetFullNameL(const TDesC& aFullName)
       
  1952 	{
       
  1953 	HBufC* fullName = aFullName.AllocL();
       
  1954 	delete iFullName;
       
  1955 	iFullName = fullName;
       
  1956 	}
       
  1957 
       
  1958 void CApaAppListServSession::RegisterListPopulationCompleteObserver(const RMessage2& aMessage)
       
  1959 	{
       
  1960 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
       
  1961 		aMessage.Panic(KApaPanicCli,EObserverAlreadyPresent);
       
  1962 	else
       
  1963 		{
       
  1964 		if(iAppList.IsFirstScanComplete())
       
  1965 			aMessage.Complete(KErrNone);
       
  1966 		else
       
  1967 			iCompletionOfListPopulationObserverMsg=aMessage;
       
  1968 		}
       
  1969 	}
       
  1970 
       
  1971 void CApaAppArcServSession::NotifyClientForCompletionOfListPopulation()
       
  1972 	{
       
  1973 	iAppListSession->NotifyClientForCompletionOfListPopulation();
       
  1974 	}
       
  1975 
       
  1976 void CApaAppListServSession::NotifyClientForCompletionOfListPopulation()
       
  1977 	{
       
  1978 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
       
  1979 		iCompletionOfListPopulationObserverMsg.Complete(KErrNone);
       
  1980 	} //lint !e1762 Suppress member function could be made const
       
  1981 
       
  1982 
       
  1983 void CApaAppListServSession::CancelListPopulationCompleteObserver()
       
  1984 	{
       
  1985 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
       
  1986 		iCompletionOfListPopulationObserverMsg.Complete(KErrCancel);
       
  1987 	} //lint !e1762 Suppress member function could be made const
       
  1988 	
       
  1989 void CApaAppArcServSession::NotifyClientOfDataMappingChange()
       
  1990 	{
       
  1991 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
       
  1992 		iMessage_NotifyOnDataMappingChange.Complete(KErrNone);
       
  1993 	} //lint !e1762 Suppress member function could be made const
       
  1994 
       
  1995 void CApaAppListServSession::MatchesSecurityPolicyL(const RMessage2& aMessage)
       
  1996 	{
       
  1997 	const TUid appUid=TUid::Uid(aMessage.Int0());
       
  1998 	TApaAppInfo* const appInfo=new(ELeave) TApaAppInfo;
       
  1999 	CleanupStack::PushL(appInfo);
       
  2000 	//Get the app info for the given App uid.
       
  2001 	GetAppInfoL(appUid, *appInfo);
       
  2002 	const TPtrC executableName(appInfo->iFullName);
       
  2003 	//Create a process only if the executable name is of non zero length
       
  2004 	if (executableName.Length() != 0)
       
  2005 		{
       
  2006 		RProcess process;
       
  2007 		TInt result = process.Create(executableName, KNullDesC);
       
  2008 		//Proceed with checking the security policy if the process is created normally
       
  2009 		if (result == KErrNone)
       
  2010 			{
       
  2011 			TPckgBuf<TSecurityPolicy> securityPolicy;
       
  2012 			aMessage.ReadL(1,securityPolicy);
       
  2013 			aMessage.Complete(securityPolicy().CheckPolicy(process));
       
  2014 			process.Close();
       
  2015 			}
       
  2016 		else
       
  2017 			aMessage.Complete(result);
       
  2018 		}
       
  2019 	else
       
  2020 		aMessage.Complete(KErrNotFound);
       
  2021 
       
  2022 	CleanupStack::PopAndDestroy(appInfo);
       
  2023 	}
       
  2024 	
       
  2025 void CApaAppListServSession::SetAppShortCaptionL(const RMessage2& aMessage)
       
  2026 	{
       
  2027 	const TUid uid=TUid::Uid(aMessage.Int0());
       
  2028 	CApaAppData* app=NULL;
       
  2029 	TApaAppEntry entry;
       
  2030 	if (!FindAppInList(app,entry,uid))
       
  2031 		User::Leave(KErrNotFound);
       
  2032 
       
  2033 	const TInt length = aMessage.GetDesLength(1);
       
  2034 	if(length < 0)
       
  2035 		User::Leave(length);
       
  2036 
       
  2037 	HBufC* const shortCaption = HBufC::NewLC(length);
       
  2038 	TPtr captionPtr(shortCaption->Des());
       
  2039 	aMessage.ReadL(1, captionPtr);
       
  2040 
       
  2041 	TLanguage appLanguage = TLanguage(aMessage.Int2());
       
  2042 	iAppList.AddCustomAppInfoInListL(uid, appLanguage, *shortCaption);
       
  2043 	if(app->ApplicationLanguage() == appLanguage)
       
  2044 		app->SetShortCaptionL(*shortCaption);
       
  2045 	else if(appLanguage==ELangNone)
       
  2046 		iAppList.UpdateAppListByShortCaptionL(); 
       
  2047 
       
  2048 	CleanupStack::PopAndDestroy(shortCaption);
       
  2049 	}
       
  2050 
       
  2051 
       
  2052 void CApaAppArcServSession::NotifyScanComplete()
       
  2053 	{
       
  2054 	iAppListSession->NotifyScanComplete();
       
  2055 	}
       
  2056 
       
  2057 void CApaAppListServSession::NotifyScanComplete()
       
  2058 	{
       
  2059 	//See if the session is intrested in scan complete notification.
       
  2060 	if (!iNotifyOnScanCompleteMsg.IsNull())
       
  2061 		{
       
  2062 		iNotifyOnScanCompleteMsg.Complete(KErrNone);
       
  2063 		}
       
  2064 	iNonNativeApplicationsManager->NotifyScanComplete();
       
  2065 	} //lint !e1762 Suppress member function could be made const
       
  2066 	
       
  2067 // TSizeArrayItemWriter
       
  2068 
       
  2069 TInt TSizeArrayItemWriter::ArrayItemCount() const
       
  2070 	{
       
  2071 	return iArray.Count();
       
  2072 	}
       
  2073 
       
  2074 TInt TSizeArrayItemWriter::ArrayItemSize() const
       
  2075 	{
       
  2076 	return sizeof(TSize);
       
  2077 	}
       
  2078 
       
  2079 void TSizeArrayItemWriter::WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const
       
  2080 	{
       
  2081 	const TSize& size = iArray[aIndex];
       
  2082 	aWriteStream.WriteUint32L(size.iWidth);
       
  2083 	aWriteStream.WriteUint32L(size.iHeight);
       
  2084 	}
       
  2085 
       
  2086 // TViewDataArrayItemWriter
       
  2087 
       
  2088 TInt TViewDataArrayItemWriter::ArrayItemCount() const
       
  2089 	{
       
  2090 	return iArray.Count();
       
  2091 	}
       
  2092 
       
  2093 TInt TViewDataArrayItemWriter::ArrayItemSize() const
       
  2094 	{
       
  2095 	return sizeof(TApaAppViewInfo);
       
  2096 	}
       
  2097 
       
  2098 void TViewDataArrayItemWriter::WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const
       
  2099 	{
       
  2100 	const CApaAppViewData& appViewData=*(iArray[aIndex]);
       
  2101 	aWriteStream << TApaAppViewInfo(appViewData.Uid(),appViewData.Caption(),appViewData.ScreenMode());
       
  2102 	}
       
  2103 
       
  2104 // TDesCArrayItemWriter
       
  2105 
       
  2106 TInt TDesCArrayItemWriter::ArrayItemCount() const
       
  2107 	{
       
  2108 	return iArray.Count();
       
  2109 	}
       
  2110 
       
  2111 TInt TDesCArrayItemWriter::ArrayItemSize() const
       
  2112 	{
       
  2113 	return sizeof(TFileName);
       
  2114 	}
       
  2115 
       
  2116 void TDesCArrayItemWriter::WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const
       
  2117 	{
       
  2118 	aWriteStream << iArray[aIndex];
       
  2119 	}
       
  2120