19
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32std.h>
|
|
20 |
#include <LiwServiceHandler.h>
|
|
21 |
#include <StifLogger.h>
|
|
22 |
|
|
23 |
#include "tsysinfoprovidertests.h"
|
|
24 |
#include "tuseractivitynotifier.h"
|
|
25 |
#include "watchtimer.h"
|
|
26 |
|
|
27 |
#include "entitykeys.h"
|
|
28 |
#include "sysinfoaiwparams.hrh"
|
|
29 |
|
|
30 |
using namespace LIW ;
|
|
31 |
using namespace SysInfo;
|
|
32 |
using namespace sysinfoaiwparams;
|
|
33 |
|
|
34 |
CTestUserActivity* CTestUserActivity::NewL(CStifLogger* aLog,TInt aTimeOut,Test_Type aType)
|
|
35 |
{
|
|
36 |
CTestUserActivity* self = new(ELeave) CTestUserActivity(aLog,aTimeOut,aType);
|
|
37 |
self->ConstructL();
|
|
38 |
return self;
|
|
39 |
}
|
|
40 |
|
|
41 |
CTestUserActivity::~CTestUserActivity()
|
|
42 |
{
|
|
43 |
Cancel();
|
|
44 |
if(iWaitSchedular->IsStarted())
|
|
45 |
iWaitSchedular->AsyncStop();
|
|
46 |
|
|
47 |
delete iTimer;
|
|
48 |
iInParamList->Reset();
|
|
49 |
iOutParamList->Reset();
|
|
50 |
iInterface->Close();
|
|
51 |
delete iServiceHandler;
|
|
52 |
delete iWaitSchedular;
|
|
53 |
|
|
54 |
}
|
|
55 |
|
|
56 |
void CTestUserActivity::ConstructL()
|
|
57 |
{
|
|
58 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait();
|
|
59 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this);
|
|
60 |
CreateInterfaceL();
|
|
61 |
CActiveScheduler::Add(this);
|
|
62 |
}
|
|
63 |
|
|
64 |
CTestUserActivity::CTestUserActivity(CStifLogger* aLog,TInt aTimeOut,
|
|
65 |
Test_Type aType) :
|
|
66 |
CActive(EPriorityStandard),
|
|
67 |
iInactivityTimeOut(aTimeOut),
|
|
68 |
iLog(aLog),
|
|
69 |
iTestType(aType)
|
|
70 |
{
|
|
71 |
}
|
|
72 |
|
|
73 |
void CTestUserActivity::DoCancel()
|
|
74 |
{
|
|
75 |
}
|
|
76 |
|
|
77 |
void CTestUserActivity::RunL()
|
|
78 |
{
|
|
79 |
TestFuncL();
|
|
80 |
}
|
|
81 |
|
|
82 |
void CTestUserActivity::Start()
|
|
83 |
{
|
|
84 |
SetActive();
|
|
85 |
TRequestStatus* temp = &iStatus;
|
|
86 |
User::RequestComplete(temp, KErrNone);
|
|
87 |
iWaitSchedular->Start();
|
|
88 |
}
|
|
89 |
|
|
90 |
TInt CTestUserActivity::Result()
|
|
91 |
{
|
|
92 |
return iResult;
|
|
93 |
}
|
|
94 |
|
|
95 |
void CTestUserActivity::TestFuncL()
|
|
96 |
{
|
|
97 |
const TInt OneSec(1000000);
|
|
98 |
iTimer->After(OneSec*iInactivityTimeOut*30);
|
|
99 |
|
|
100 |
// REGISTER FOR NOTIFICATION.
|
|
101 |
//-------------------------------------------------------------------------
|
|
102 |
{
|
|
103 |
iLog->Log( _L("Issueing Notification request .. InactivityTimeOut: %d"),iInactivityTimeOut);
|
|
104 |
TInt RetVal(PASS);
|
|
105 |
TInt32 Err;
|
|
106 |
|
|
107 |
iOutParamList->Reset();
|
|
108 |
iInParamList->Reset();
|
|
109 |
|
|
110 |
CLiwMap* inmap = CLiwDefaultMap::NewL();
|
|
111 |
|
|
112 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KDisplay)));
|
|
113 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KUserInactivity)));
|
|
114 |
|
|
115 |
inmap->InsertL(KStatus,TLiwVariant((TInt32)iInactivityTimeOut));
|
|
116 |
iInParamList->AppendL(TLiwGenericParam(KSysData,TLiwVariant(inmap)));
|
|
117 |
|
|
118 |
iInterface->ExecuteCmdL(KGetNotification,*iInParamList,*iOutParamList,KLiwOptASyncronous,this);
|
|
119 |
|
|
120 |
RetVal |= CheckErrorCode(*iOutParamList,Err);
|
|
121 |
if ( Err )
|
|
122 |
{
|
|
123 |
iLog->Log( _L("GetNotification retured error : %d"),Err );
|
|
124 |
User::Leave(Err);
|
|
125 |
}
|
|
126 |
|
|
127 |
TInt index=0;
|
|
128 |
const TLiwGenericParam* ret_val = iOutParamList->FindFirst(index,KTransactionId);
|
|
129 |
if(!ret_val)
|
|
130 |
{
|
|
131 |
iLog->Log( _L("Transaction ID not found"));
|
|
132 |
User::Leave(FAIL);
|
|
133 |
}
|
|
134 |
else
|
|
135 |
{
|
|
136 |
iTransID = ret_val->Value().AsTInt32();
|
|
137 |
iLog->Log( _L("TRANSACTION ID : %d"),iTransID );
|
|
138 |
}
|
|
139 |
|
|
140 |
inmap->DecRef();
|
|
141 |
}
|
|
142 |
|
|
143 |
iOutParamList->Reset();
|
|
144 |
iInParamList->Reset();
|
|
145 |
|
|
146 |
}
|
|
147 |
|
|
148 |
TInt CTestUserActivity::HandleNotifyL( TInt aTransID, TInt aEventId,
|
|
149 |
CLiwGenericParamList& aEventParamList,
|
|
150 |
const CLiwGenericParamList& /*aInParamList*/)
|
|
151 |
{
|
|
152 |
aEventId=aEventId;
|
|
153 |
delete iTimer;
|
|
154 |
iTimer = NULL;
|
|
155 |
{
|
|
156 |
TInt index=0;
|
|
157 |
TPtrC entity,key;
|
|
158 |
TInt32 status;
|
|
159 |
const TLiwGenericParam* ret_val = aEventParamList.FindFirst(index,KReturnValue);
|
|
160 |
if(!ret_val)
|
|
161 |
{
|
|
162 |
iLog->Log( _L("Return value parameter not found"));
|
|
163 |
User::Leave(FAIL);
|
|
164 |
}
|
|
165 |
else
|
|
166 |
{
|
|
167 |
const CLiwMap* outmap = ret_val->Value().AsMap();
|
|
168 |
TLiwVariant ventity,vkey,vstatus;
|
|
169 |
if( !outmap->FindL(KEntity,ventity) )
|
|
170 |
{
|
|
171 |
iLog->Log( _L("Entity parameter not found"));
|
|
172 |
User::Leave(FAIL);
|
|
173 |
}
|
|
174 |
if( !outmap->FindL(KKey,vkey) )
|
|
175 |
{
|
|
176 |
iLog->Log( _L("Key parameter not found"));
|
|
177 |
User::Leave(FAIL);
|
|
178 |
}
|
|
179 |
|
|
180 |
if( !outmap->FindL(KStatus,vstatus) )
|
|
181 |
{
|
|
182 |
iLog->Log( _L("Key parameter not found"));
|
|
183 |
User::Leave(FAIL);
|
|
184 |
}
|
|
185 |
ventity.Get(entity);
|
|
186 |
vkey.Get(key);
|
|
187 |
status = vstatus.AsTInt32();
|
|
188 |
|
|
189 |
// ((CLiwMap)outmap)->DecRef();
|
|
190 |
|
|
191 |
if( !(entity.Compare(KDisplay) || key.Compare(KUserInactivity)) )
|
|
192 |
{
|
|
193 |
if(!(aTransID == iTransID))
|
|
194 |
{
|
|
195 |
iLog->Log(_L("Incorrect TransactionID: %d"),aTransID);
|
|
196 |
iResult |= FAIL;
|
|
197 |
}
|
|
198 |
|
|
199 |
iLog->Log(_L("UserActivity/Inactivity Notification.."));
|
|
200 |
if(status)
|
|
201 |
iLog->Log(_L("User Inactivity Detected.."));
|
|
202 |
else
|
|
203 |
iLog->Log(_L("User Activity Detected.."));
|
|
204 |
|
|
205 |
iResult |= PASS;
|
|
206 |
}
|
|
207 |
|
|
208 |
ventity.Reset();
|
|
209 |
vkey.Reset();
|
|
210 |
|
|
211 |
if (ETESTACTIVITY == iTestType)
|
|
212 |
{
|
|
213 |
if(status)
|
|
214 |
{
|
|
215 |
iLog->Log(_L("Waiting for user activity"));
|
|
216 |
return KErrNone;
|
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
|
220 |
iLog->Log(_L("User Activity Detected.."));
|
|
221 |
}
|
|
222 |
iResult |= PASS;
|
|
223 |
}
|
|
224 |
}
|
|
225 |
}
|
|
226 |
|
|
227 |
iResult |= PASS;
|
|
228 |
iWaitSchedular->AsyncStop();
|
|
229 |
return KErrNone;
|
|
230 |
}
|
|
231 |
|
|
232 |
void CTestUserActivity::HandleTimeOut()
|
|
233 |
{
|
|
234 |
iLog->Log(_L("TimeOut reached. Inactivity not detected.."));
|
|
235 |
/* iSysInfoService->Cancel(1);
|
|
236 |
*/
|
|
237 |
iResult = FAIL;
|
|
238 |
iWaitSchedular->AsyncStop();
|
|
239 |
}
|
|
240 |
|
|
241 |
void CTestUserActivity::CreateInterfaceL()
|
|
242 |
{
|
|
243 |
iServiceHandler = CLiwServiceHandler::NewL();
|
|
244 |
CleanupStack::PushL(iServiceHandler);
|
|
245 |
|
|
246 |
iInParamList = &(iServiceHandler->InParamListL());
|
|
247 |
iOutParamList = &(iServiceHandler->OutParamListL());
|
|
248 |
|
|
249 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1,KIDataSource,KService);
|
|
250 |
CleanupStack::PushL(crit);
|
|
251 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase));
|
|
252 |
RCriteriaArray a;
|
|
253 |
CleanupClosePushL(a);
|
|
254 |
a.AppendL(crit);
|
|
255 |
iServiceHandler->AttachL(a);
|
|
256 |
iServiceHandler->ExecuteServiceCmdL(*crit,*iInParamList,*iOutParamList);
|
|
257 |
|
|
258 |
TInt Index = 0;
|
|
259 |
const TLiwGenericParam* param = iOutParamList->FindFirst(Index,KIDataSource);
|
|
260 |
if(!param)
|
|
261 |
{
|
|
262 |
iLog->Log( _L("Interface Not found "));
|
|
263 |
User::Leave(KErrGeneral);
|
|
264 |
}
|
|
265 |
|
|
266 |
iInterface = param->Value().AsInterface();
|
|
267 |
CleanupStack::PopAndDestroy(&a);
|
|
268 |
CleanupStack::PopAndDestroy (crit);
|
|
269 |
|
|
270 |
CleanupStack::Pop (iServiceHandler);
|
|
271 |
}
|
|
272 |
|
|
273 |
TInt CTestUserActivity::CheckErrorCode( const CLiwGenericParamList& aOutList, TInt32 &aError )
|
|
274 |
{
|
|
275 |
TInt Index = 0;
|
|
276 |
const TLiwGenericParam* errcode = aOutList.FindFirst(Index,KErrorCode);
|
|
277 |
if ( KErrNotFound == Index )
|
|
278 |
{
|
|
279 |
iLog->Log( _L("ErrorCode not found in output ArgList") );
|
|
280 |
return FAIL;
|
|
281 |
}
|
|
282 |
else
|
|
283 |
errcode->Value().Get(aError);
|
|
284 |
return PASS;
|
|
285 |
}
|
|
286 |
//End of file.
|