os/security/authorisation/userpromptservice/policies/source/policyevaluator.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/policies/source/policyevaluator.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,197 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <ups/policyevaluator.h>
    1.23 +#include <ups/upserr.h>
    1.24 +#include <ecom/ecom.h>
    1.25 +#include "upslog.h"
    1.26 +
    1.27 +using namespace UserPromptService;
    1.28 +
    1.29 +/**
    1.30 +Default implementation of a policy evaluator. 
    1.31 +This is returned if no policy evaluator is defined in the policy file OR
    1.32 +the policy evaluator implementation UID is zero.
    1.33 +*/
    1.34 +NONSHARABLE_CLASS(CDefaultPolicyEvaluator) : public CPolicyEvaluator 
    1.35 +	{
    1.36 +public:
    1.37 +	static CDefaultPolicyEvaluator* NewL();
    1.38 +	
    1.39 +	void GenerateFingerprints(
    1.40 +		const CPromptRequest& aRequest, const CPolicy& aPolicy,
    1.41 +		RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& aClientEntity, 
    1.42 +		const TAny*& aDialogCreatorParams,
    1.43 +		TRequestStatus& aStatus);
    1.44 +	
    1.45 +	// Empty implementations of CActive pure virtual functions
    1.46 +	// RunL is never called because the request is completed immediately.
    1.47 +	void RunL() {};
    1.48 +	void DoCancel() {};
    1.49 +	
    1.50 +	~CDefaultPolicyEvaluator();
    1.51 +	
    1.52 +private:
    1.53 +	CDefaultPolicyEvaluator();
    1.54 +	};
    1.55 +
    1.56 +EXPORT_C CPolicyEvaluator::CPolicyEvaluator()
    1.57 +/**
    1.58 +Constructor
    1.59 +*/
    1.60 +: CActive(EPriorityStandard)
    1.61 +	{
    1.62 +	}
    1.63 +
    1.64 +EXPORT_C CPolicyEvaluator::~CPolicyEvaluator()
    1.65 +/**
    1.66 +Destructor
    1.67 +*/
    1.68 +	{
    1.69 +	REComSession::DestroyedImplementation(iDtor_ID_Key);
    1.70 +	}
    1.71 +	
    1.72 +EXPORT_C CPolicyEvaluator* CPolicyEvaluator::NewL(const TUid& aPolicyEvaluatorImplementationId)
    1.73 +/**
    1.74 +Creates a new policy evaluator.
    1.75 +@param	aPolicyEvaluatorImplementationId	The UID of the policy evaluator implemenation
    1.76 +											as specified in the policy file.
    1.77 +
    1.78 +@return A pointer to the new dialog creator implementation.
    1.79 +*/
    1.80 +	{
    1.81 +	if (aPolicyEvaluatorImplementationId.iUid == 0)
    1.82 +		{
    1.83 +		DEBUG_PRINTF(_L8("Instantiating default policy evaluator"));
    1.84 +		return CDefaultPolicyEvaluator::NewL();
    1.85 +		}
    1.86 +	
    1.87 +	TAny* plugin(0);
    1.88 +	DEBUG_PRINTF2(_L8("Instantiating policy evaluator 0x%08x"), aPolicyEvaluatorImplementationId);
    1.89 +	TRAPD(err, plugin = 
    1.90 +	REComSession::CreateImplementationL(aPolicyEvaluatorImplementationId,
    1.91 +		_FOFF(CPolicyEvaluator,iDtor_ID_Key)));
    1.92 +
    1.93 +	if (err != KErrNone)
    1.94 +		{
    1.95 +		DEBUG_PRINTF3(_L8("Failed to instantiate policy evaluator 0x%08x, err = %d"),
    1.96 +					  aPolicyEvaluatorImplementationId.iUid, err);
    1.97 +		}
    1.98 +
    1.99 +	if (err == KErrNotFound)
   1.100 +		{
   1.101 +		err = KErrUpsMissingPolicyEvaluator;  
   1.102 +		}
   1.103 +	User::LeaveIfError(err);
   1.104 +	return reinterpret_cast<CPolicyEvaluator*>(plugin);		
   1.105 +	}
   1.106 +
   1.107 +/**
   1.108 +If a decision record matching one of the fingerprints created by \ref CPolicyEvaluator::GenerateFingerprints
   1.109 +was found then this method will be invoked. This allows the policy evaluator 
   1.110 +to instruct the user prompt service to ignore the result of the decision record and prompt 
   1.111 +the user.\p
   1.112 +This functionality could be used to trigger periodic prompts if an application
   1.113 +makes very high usage of a service e.g. after 100 SMS messages have been sent. 
   1.114 +The usage could be tracked externally or via the evaluatorInfo field in the decision record.\n
   1.115 +N.B. The User Prompt Service does not mandate the contents or usage of the evaluatorInfo field.
   1.116 +
   1.117 +- The default implementation CPolicyEvaluator::ForcePromptL always returns EFalse and does
   1.118 +  not modifiy aNewEvaluatorInfo.
   1.119 +
   1.120 +@param	aDecision			The first decision record that matched a fingerprint generated by
   1.121 +							\ref CPolicyEvaluator::GenerateFingerprints
   1.122 +@param	aNewEvaluatorInfo	A reference to a copy of the evaluatorInfo field from the decision record.
   1.123 +							If this method modifies this value then this field will be updated in the
   1.124 +							decision record regardless of whether a prompt is required.
   1.125 +@return						ETrue if a prompt should be displayed; otherwise, 
   1.126 +							EFalse if the result of the decision record should be used.
   1.127 +*/
   1.128 +EXPORT_C TBool CPolicyEvaluator::ForcePromptL(const CDecisionRecord& aDecision, TUint& aNewEvaluatorInfo)
   1.129 +	{
   1.130 +	(void) aDecision;
   1.131 +	(void) aNewEvaluatorInfo;
   1.132 +	return EFalse;
   1.133 +	}
   1.134 +
   1.135 +EXPORT_C TInt CPolicyEvaluator::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1)
   1.136 +/**
   1.137 +Allows extension of this interface. Calls Extension_
   1.138 +
   1.139 +@param aExtensionId		The UID of the interface to instantiate.
   1.140 +@param a0				A reference to a pointer that should be set to the newly
   1.141 +						instantiated object.
   1.142 +@param a1				Data specific to the instantiate of the specified interface.
   1.143 +
   1.144 +@return KErrNone if the extension is supported or KErrNotSupported if the extension is not
   1.145 +		recognised; otherwise, a system wide error may be returned.
   1.146 +*/
   1.147 +	{
   1.148 +	return Extension_(aExtensionId, a0, a1);
   1.149 +	}
   1.150 +
   1.151 +EXPORT_C TInt CPolicyEvaluator::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
   1.152 +	{
   1.153 +	return CActive::Extension_(aExtensionId, a0, a1);
   1.154 +	}
   1.155 +
   1.156 +CDefaultPolicyEvaluator* CDefaultPolicyEvaluator::NewL() 
   1.157 +/**
   1.158 +Factory method that creates a new default policy evaluator object.
   1.159 +@return A pointer to the new default policy evaluator object.
   1.160 +*/
   1.161 +	{
   1.162 +	CDefaultPolicyEvaluator* self = new(ELeave) CDefaultPolicyEvaluator();
   1.163 +	return self;
   1.164 +	}
   1.165 +
   1.166 +CDefaultPolicyEvaluator::CDefaultPolicyEvaluator()
   1.167 +/**
   1.168 +Constructor
   1.169 +*/
   1.170 +	: CPolicyEvaluator()
   1.171 +	{
   1.172 +	CActiveScheduler::Add(this);
   1.173 +	}
   1.174 +
   1.175 +CDefaultPolicyEvaluator::~CDefaultPolicyEvaluator()
   1.176 +/**
   1.177 +Destructor
   1.178 +*/
   1.179 +	{
   1.180 +	Deque();
   1.181 +	}
   1.182 +	
   1.183 +void CDefaultPolicyEvaluator::GenerateFingerprints(
   1.184 +	const CPromptRequest& /* aRequest */, const CPolicy& /* aPolicy */,
   1.185 +	RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& /* aClientEntity */, 
   1.186 +	const TAny*& /* aDialogCreatorParams */,
   1.187 +	TRequestStatus& aStatus)
   1.188 +/**
   1.189 +Returns a single, null fingerprint and completes immediately.
   1.190 +*/
   1.191 +	{
   1.192 +	CFingerprint* f(0);
   1.193 +	TRAPD(retVal, f = CFingerprint::NewLC(KNullDesC8, KNullDesC);
   1.194 +			   aFingerprints.AppendL(f); 
   1.195 +			   CleanupStack::Pop(f));
   1.196 +	
   1.197 +	TRequestStatus *status = &aStatus;
   1.198 +	*status = KRequestPending;	
   1.199 +	User::RequestComplete(status, retVal);
   1.200 +	}