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