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