os/security/authorisation/userpromptservice/policies/source/policyevaluator.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <ups/policyevaluator.h>
    20 #include <ups/upserr.h>
    21 #include <ecom/ecom.h>
    22 #include "upslog.h"
    23 
    24 using namespace UserPromptService;
    25 
    26 /**
    27 Default implementation of a policy evaluator. 
    28 This is returned if no policy evaluator is defined in the policy file OR
    29 the policy evaluator implementation UID is zero.
    30 */
    31 NONSHARABLE_CLASS(CDefaultPolicyEvaluator) : public CPolicyEvaluator 
    32 	{
    33 public:
    34 	static CDefaultPolicyEvaluator* NewL();
    35 	
    36 	void GenerateFingerprints(
    37 		const CPromptRequest& aRequest, const CPolicy& aPolicy,
    38 		RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& aClientEntity, 
    39 		const TAny*& aDialogCreatorParams,
    40 		TRequestStatus& aStatus);
    41 	
    42 	// Empty implementations of CActive pure virtual functions
    43 	// RunL is never called because the request is completed immediately.
    44 	void RunL() {};
    45 	void DoCancel() {};
    46 	
    47 	~CDefaultPolicyEvaluator();
    48 	
    49 private:
    50 	CDefaultPolicyEvaluator();
    51 	};
    52 
    53 EXPORT_C CPolicyEvaluator::CPolicyEvaluator()
    54 /**
    55 Constructor
    56 */
    57 : CActive(EPriorityStandard)
    58 	{
    59 	}
    60 
    61 EXPORT_C CPolicyEvaluator::~CPolicyEvaluator()
    62 /**
    63 Destructor
    64 */
    65 	{
    66 	REComSession::DestroyedImplementation(iDtor_ID_Key);
    67 	}
    68 	
    69 EXPORT_C CPolicyEvaluator* CPolicyEvaluator::NewL(const TUid& aPolicyEvaluatorImplementationId)
    70 /**
    71 Creates a new policy evaluator.
    72 @param	aPolicyEvaluatorImplementationId	The UID of the policy evaluator implemenation
    73 											as specified in the policy file.
    74 
    75 @return A pointer to the new dialog creator implementation.
    76 */
    77 	{
    78 	if (aPolicyEvaluatorImplementationId.iUid == 0)
    79 		{
    80 		DEBUG_PRINTF(_L8("Instantiating default policy evaluator"));
    81 		return CDefaultPolicyEvaluator::NewL();
    82 		}
    83 	
    84 	TAny* plugin(0);
    85 	DEBUG_PRINTF2(_L8("Instantiating policy evaluator 0x%08x"), aPolicyEvaluatorImplementationId);
    86 	TRAPD(err, plugin = 
    87 	REComSession::CreateImplementationL(aPolicyEvaluatorImplementationId,
    88 		_FOFF(CPolicyEvaluator,iDtor_ID_Key)));
    89 
    90 	if (err != KErrNone)
    91 		{
    92 		DEBUG_PRINTF3(_L8("Failed to instantiate policy evaluator 0x%08x, err = %d"),
    93 					  aPolicyEvaluatorImplementationId.iUid, err);
    94 		}
    95 
    96 	if (err == KErrNotFound)
    97 		{
    98 		err = KErrUpsMissingPolicyEvaluator;  
    99 		}
   100 	User::LeaveIfError(err);
   101 	return reinterpret_cast<CPolicyEvaluator*>(plugin);		
   102 	}
   103 
   104 /**
   105 If a decision record matching one of the fingerprints created by \ref CPolicyEvaluator::GenerateFingerprints
   106 was found then this method will be invoked. This allows the policy evaluator 
   107 to instruct the user prompt service to ignore the result of the decision record and prompt 
   108 the user.\p
   109 This functionality could be used to trigger periodic prompts if an application
   110 makes very high usage of a service e.g. after 100 SMS messages have been sent. 
   111 The usage could be tracked externally or via the evaluatorInfo field in the decision record.\n
   112 N.B. The User Prompt Service does not mandate the contents or usage of the evaluatorInfo field.
   113 
   114 - The default implementation CPolicyEvaluator::ForcePromptL always returns EFalse and does
   115   not modifiy aNewEvaluatorInfo.
   116 
   117 @param	aDecision			The first decision record that matched a fingerprint generated by
   118 							\ref CPolicyEvaluator::GenerateFingerprints
   119 @param	aNewEvaluatorInfo	A reference to a copy of the evaluatorInfo field from the decision record.
   120 							If this method modifies this value then this field will be updated in the
   121 							decision record regardless of whether a prompt is required.
   122 @return						ETrue if a prompt should be displayed; otherwise, 
   123 							EFalse if the result of the decision record should be used.
   124 */
   125 EXPORT_C TBool CPolicyEvaluator::ForcePromptL(const CDecisionRecord& aDecision, TUint& aNewEvaluatorInfo)
   126 	{
   127 	(void) aDecision;
   128 	(void) aNewEvaluatorInfo;
   129 	return EFalse;
   130 	}
   131 
   132 EXPORT_C TInt CPolicyEvaluator::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1)
   133 /**
   134 Allows extension of this interface. Calls Extension_
   135 
   136 @param aExtensionId		The UID of the interface to instantiate.
   137 @param a0				A reference to a pointer that should be set to the newly
   138 						instantiated object.
   139 @param a1				Data specific to the instantiate of the specified interface.
   140 
   141 @return KErrNone if the extension is supported or KErrNotSupported if the extension is not
   142 		recognised; otherwise, a system wide error may be returned.
   143 */
   144 	{
   145 	return Extension_(aExtensionId, a0, a1);
   146 	}
   147 
   148 EXPORT_C TInt CPolicyEvaluator::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
   149 	{
   150 	return CActive::Extension_(aExtensionId, a0, a1);
   151 	}
   152 
   153 CDefaultPolicyEvaluator* CDefaultPolicyEvaluator::NewL() 
   154 /**
   155 Factory method that creates a new default policy evaluator object.
   156 @return A pointer to the new default policy evaluator object.
   157 */
   158 	{
   159 	CDefaultPolicyEvaluator* self = new(ELeave) CDefaultPolicyEvaluator();
   160 	return self;
   161 	}
   162 
   163 CDefaultPolicyEvaluator::CDefaultPolicyEvaluator()
   164 /**
   165 Constructor
   166 */
   167 	: CPolicyEvaluator()
   168 	{
   169 	CActiveScheduler::Add(this);
   170 	}
   171 
   172 CDefaultPolicyEvaluator::~CDefaultPolicyEvaluator()
   173 /**
   174 Destructor
   175 */
   176 	{
   177 	Deque();
   178 	}
   179 	
   180 void CDefaultPolicyEvaluator::GenerateFingerprints(
   181 	const CPromptRequest& /* aRequest */, const CPolicy& /* aPolicy */,
   182 	RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& /* aClientEntity */, 
   183 	const TAny*& /* aDialogCreatorParams */,
   184 	TRequestStatus& aStatus)
   185 /**
   186 Returns a single, null fingerprint and completes immediately.
   187 */
   188 	{
   189 	CFingerprint* f(0);
   190 	TRAPD(retVal, f = CFingerprint::NewLC(KNullDesC8, KNullDesC);
   191 			   aFingerprints.AppendL(f); 
   192 			   CleanupStack::Pop(f));
   193 	
   194 	TRequestStatus *status = &aStatus;
   195 	*status = KRequestPending;	
   196 	User::RequestComplete(status, retVal);
   197 	}