Privacy Request API Tutorial
This topic describes how to use the Privacy
Request API.
The reader must be familiar with the Privacy Protocol Module and the Privacy Request API.
When LBS is configured to load the Privacy Protocol Module, it handles only privacy requests and does not calculate position fixes. It is the responsibility of licensee domestic OS components to obtain the device's position. The Privacy Request API provides the means to send privacy requests into the LBS subsystem.
To use the Network Privacy API a licensee must create a client component that runs in the licensee domestic OS. This component receives privacy and location requests from the network or from an installed application and forwards them to the LBS subsystem via the Privacy Request API.
The Privacy Request API is only available with the Privacy Protocol Module. The first privacy request sent via the Network Privacy API causes the LBS subsystem components to be started.
Many of the implementation details of creating a Privacy Request API client are licensee-specific. Generally, the client must:
Listen for privacy and location requests received from the client.
Use the Privacy Request API to forward privacy requests to the LBS subsystem.
Receive responses to privacy requests from the LBS subsystem via the Privacy Request API and return them to the client.
If a privacy request is accepted, forward the subsequent location request to a component in the licensee domestic OS so that a position fix can be obtained.
The steps that follow describe only the interactions of the client with the Privacy Request API.
- Create a Privacy Request API client. The code example below shows a simple implementation of an MLbsPrivacyRequestObserver subclass that uses the Privacy Request API. Such a class could be the basis of an observer class in a licensee client application.
#ifndef CMYPRIVACYREQUESTLISTENER_H_
#define CMYPRIVACYREQUESTLISTENER_H_
#include <lbsprivacyrequest.h>
#include <lbsloccommon.h>
class CMyPrivacyRequestObserver : public MLbsPrivacyRequestObserver
{
public:
static CMyPrivacyRequestObserver* NewL();
virtual ~CMyPrivacyRequestObserver();
// From MLbsPrivacyRequestObserver
public:
void OnPrivacyResponse(TLbsPrivacyRequestId aRequestId, const TLbsPrivacyResponse& aResponse, TInt aError);
public:
void VerifyPrivacyRequest(const TLbsExternalRequestInfo& aInfo);
void NotifyPrivacyRequest(const TLbsExternalRequestInfo& aInfo);
void CancelPrivacyRequest(TLbsPrivacyRequestId& aRequestId);
void TimeoutPrivacyRequest(TLbsPrivacyRequestId& aRequestId);
protected:
CMyPrivacyRequestObserver();
private:
CLbsPrivacyRequest* iPrivacy;
TLbsPrivacyRequestId iRequestId; // This demo client just stores a single request ID
void ConstructL();
};
#endif /*CMYPRIVACYREQUESTLISTENER_H_*/
The code below shows the creation of a CLbsPrivacyRequest object in the second phase constructor of the observer. The LBS subsystem is transient when it uses the Privacy Protocol Module. Creating an instance of CMyPrivacyRequestObserver does not cause the LBS subsystem to be started.
CMyPrivacyRequestObserver* CMyPrivacyRequestObserver::NewL()
{
CMyPrivacyRequestObserver* listener =
new (ELeave)CMyPrivacyRequestObserver();
CleanupStack::PushL(listener);
listener->ConstructL();
CleanupStack::Pop(listener);
return listener;
}
void CMyPrivacyRequestObserver::ConstructL()
{
iPrivacy = CLbsPrivacyRequest::NewL(*this);
}
- Write code to send a privacy verification request. The licensee client receives a privacy verification request from the network or a local application. The privacy request requires user verification. The following describes the steps the licensee client application performs for a privacy verification request:
The client creates an instance of class TLbsExternalRequestInfo (or TLbsExternalRequestInfo2) and populates it with the privacy request data. For a local privacy request, the client must call TLbsExternalRequestInfo::SetRequestSource() with a parameter of TLbsExternalRequestInfo::ERequestSourceLocal. The client must have the capabilities Location and ReadDeviceData. For a privacy request from the network, a parameter of TLbsExternalRequestInfo::ERequestSourceNetwork must be passed. The client must have the capabilities Location, ReadDeviceData and NetworkServices. The client creates an instance of an object of class TLbsPrivacyRequest and defines the privacy advice and privacy action. For a privacy verification request, the privacy advice is set to TLbsPrivacyRequest::ERequestAdviceVerify.
The client calls CLbsPrivacyRequest::NewPrivacyRequest(). This method is asynchronous and non-blocking. The client can process multiple privacy requests by calling NewPrivacyRequest() multiple times. Each request is identified by a unique request ID which is returned by LBS as an output parameter. The LBS subsystem is started if it is not running when a request is made.
When the privacy request is completed, the method MLbsPrivacyRequestObserver::OnPrivacyResponse() is called on the client observer. The licensee client sends the privacy response to the local application or the network (whichever made the privacy request).
The following code example demonstrates how to use the Privacy Request API to verify a privacy request.
// In this example, the TLbsExternalRequestInfo object
// is created by the client application
void CMyPrivacyRequestObserver::VerifyPrivacyRequest(const TLbsExternalRequestInfo& aInfo)
{
// Example shows how to set the privacy advice to verify the request
// and set the privacy action to reject if there is no privacy response
TLbsPrivacyRequest privacy;
privacy.SetRequestAdvice(TLbsPrivacyRequest::ERequestAdviceVerify);
privacy.SetRequestAction(TLbsPrivacyRequest::ERequestActionReject);
TInt err = iPrivacy->NewPrivacyRequest(iRequestId, privacy, aInfo);
if (err != KErrNone)
{
// Error could be KErrArgument if incorrect parameters passed
// or any other Symbian error code
}
}
MLbsPrivacyRequestObserver::OnPrivacyResponse() is called to complete the request.
void CMyPrivacyRequestObserver::OnPrivacyResponse(TLbsPrivacyRequestId aRequestId, const TLbsPrivacyResponse& aResponse, TInt aError)
{
// Forward privacy response to client then call CompleteRequest...
iPrivacy->CompleteRequest(aRequestId, KErrNone);
}
- Write code to send a privacy notification request. The licensee client receives a privacy request from the network or a local application. The privacy request does not require verification. The following describes the steps the licensee client application performs for a privacy notification request:
The client creates an instance of class TLbsExternalRequestInfo as described for privacy verification in the previous section. The client creates an instance of an object of class TLbsPrivacyRequest and defines the privacy advice and privacy action. For a privacy notification request, the privacy advice is set to TLbsPrivacyRequest::ERequestAdviceNotify.
The client calls CLbsPrivacyRequest::NewPrivacyRequest(). This method is asynchronous and non-blocking. The client can process multiple privacy requests by calling NewPrivacyRequest() multiple times. Each request is identified by a unique request ID which must be passed as a parameter. The LBS subsystem is started if it is not running when a request is made.
The following code example demonstrates how to use the Privacy Request API to notify a privacy request.
// In this example, the TLbsExternalRequestInfo object
// is created by the client application
void CMyPrivacyRequestObserver::NotifyPrivacyRequest(const TLbsExternalRequestInfo& aInfo)
{
// Example shows how to set the privacy advice to verify the request
// and set the privacy action to reject if there is no privacy response
TLbsPrivacyRequest privacy;
privacy.SetRequestAdvice(TLbsPrivacyRequest::ERequestAdviceNotify);
privacy.SetRequestAction(TLbsPrivacyRequest::ERequestActionReject);
TInt err = iPrivacy->NewPrivacyRequest(iRequestId, privacy, aInfo);
if (err != KErrNone)
{
// Error could be KErrArgument if incorrect parameters passed
// or any other Symbian error code
}
}
MLbsPrivacyRequestObserver::OnPrivacyResponse() is called to complete the request.
- Write code to cancel a pending privacy verification request. The code example below shows how a client can cancel an outstanding request by calling CLbsPrivacyRequest::CompleteRequest().
void CMyPrivacyRequestObserver::CancelPrivacyRequest(TLbsPrivacyRequestId& aRequestId)
{
iPrivacy->CompleteRequest(aRequestId, KErrCancel);
}
- Write code to send a timeout notification. The code example below shows how a request can be timed out. The timeout is sent to the LBS subsystem by calling CLbsPrivacyRequest::CompleteRequest().
void CMyPrivacyRequestObserver::TimeoutPrivacyRequest(TLbsPrivacyRequestId& aRequestId)
{
iPrivacy->CompleteRequest(aRequestId, KErrTimedOut);
}
- Define client capabilities. The following is a simple MMP file for the client. The header files for the Privacy Request API are located at \epoc32\include\lbs and the client links to lbsprivacyrequest.lib. All clients require the capabilities Location and ReadDeviceData. Clients that create network privacy requests also require the capability NetworkServices.
TARGET PrivacyRequestAPI_Example.exe
TARGETTYPE exe
UID 0 0x12345678
USERINCLUDE ..\inc
SYSTEMINCLUDE \epoc32\include \epoc32\include\lbs
SOURCEPATH ..\src
SOURCE PrivacyRequestAPI_Example.cpp CMyPrivacyRequestListener.cpp
LIBRARY euser.lib lbsprivacyrequest.lib
CAPABILITY Location ReadDeviceData NetworkServices
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.