|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 // #include "xqservicelog.h" |
|
23 |
|
24 #include <QApplication> |
|
25 #include <QKeyEvent> |
|
26 #include <QEvent> |
|
27 #include <QLabel> |
|
28 #include <QVBoxLayout> |
|
29 #include <QStackedWidget> |
|
30 #include <QImageReader> |
|
31 #include <QDebug> |
|
32 #include <QTimer> |
|
33 #include <QPushButton> |
|
34 #include <QLineEdit> |
|
35 #include <QListView> |
|
36 #include <QMessageBox> |
|
37 #include <QToolButton> |
|
38 #include <QSymbianEvent> |
|
39 #include <QMainWindow> |
|
40 #include <qvaluespacesubscriber.h> |
|
41 #include <qvaluespacepublisher.h> |
|
42 |
|
43 QTM_USE_NAMESPACE |
|
44 |
|
45 #include <HbIndicator> |
|
46 #include <hbdevicemessagebox.h> |
|
47 |
|
48 #include "../../SecUi/inc/SecQueryUi.h" |
|
49 |
|
50 #include <lockappclientserver.h> |
|
51 |
|
52 #include <xqsharablefile.h> |
|
53 |
|
54 #include <QGraphicsLinearLayout> |
|
55 |
|
56 #include <hblabel.h> |
|
57 |
|
58 #include "AutolockSrv.h" |
|
59 #include <xqserviceutil.h> |
|
60 |
|
61 #include "autolockuseractivityservice.h" |
|
62 |
|
63 #include <settingsinternalcrkeys.h> // CenRep keys |
|
64 |
|
65 #include <W32STD.H> |
|
66 #include <eikenv.h> |
|
67 |
|
68 #include <qapplication.h> |
|
69 |
|
70 #include <secuisecuritysettings.h> |
|
71 #include <secui.h> |
|
72 #include <secuisecurityhandler.h> |
|
73 #include <etelmm.h> |
|
74 #include <rmmcustomapi.h> |
|
75 |
|
76 #include <qvaluespacesubscriber.h> |
|
77 |
|
78 #include <hwrmlightdomaincrkeys.h> |
|
79 #include <ProfileEngineSDKCRKeys.h> |
|
80 #include <e32property.h> |
|
81 #include <coreapplicationuisdomainpskeys.h> |
|
82 #include "../../../inc/securityuisprivatepskeys.h" |
|
83 #include <avkondomainpskeys.h> |
|
84 |
|
85 #include <hbdevicedialog.h> |
|
86 |
|
87 const TInt KPhoneIndex( 0 ); |
|
88 const TInt KTriesToConnectServer( 2 ); |
|
89 const TInt KTimeBeforeRetryingServerConnection( 50000 ); |
|
90 |
|
91 #define ESecUiTypeLock 0x00100000 |
|
92 |
|
93 _LIT( KMmTsyModuleName, "PhoneTsy"); |
|
94 |
|
95 |
|
96 #define XQSERVICE_DEBUG_PRINT(a) qDebug() << (a) |
|
97 |
|
98 AutolockSrv::AutolockSrv(QWidget *parent, Qt::WFlags f) |
|
99 : QWidget(parent, f), |
|
100 mService(NULL) |
|
101 { |
|
102 XQSERVICE_DEBUG_PRINT("AutolockSrv::AutolockSrv"); |
|
103 RDEBUG( "start", 0 ); |
|
104 mService = new AutolockSrvService(this); |
|
105 |
|
106 /* Adjust the palette */ |
|
107 #if defined(Q_WS_S60) |
|
108 RDEBUG( "Q_WS_S60", 1 ); |
|
109 QPalette p = qApp->palette(); |
|
110 QColor color(192,192,192); |
|
111 QColor bg(201,250,250); |
|
112 p.setColor(QPalette::Highlight, color.lighter(200)); |
|
113 p.setColor(QPalette::Text, Qt::black); |
|
114 p.setColor(QPalette::Base, bg); |
|
115 p.setColor(QPalette::WindowText, Qt::black); |
|
116 p.setColor(QPalette::Window, bg); |
|
117 p.setColor(QPalette::ButtonText, Qt::black); |
|
118 p.setColor(QPalette::Button, color.lighter(150)); |
|
119 p.setColor(QPalette::Link, QColor(240,40,40)); |
|
120 |
|
121 qApp->setPalette(p); |
|
122 #endif |
|
123 |
|
124 QPushButton *unlockButton = new QPushButton(tr("Unlock")); |
|
125 QPushButton *unguardButton = new QPushButton(tr("Unguard")); |
|
126 QPushButton *lockButton = new QPushButton(tr("Lock")); |
|
127 QPushButton *quitButton = new QPushButton(tr("Quit")); |
|
128 QPushButton *test1Button = new QPushButton(tr("Autolock 10 seconds")); |
|
129 QPushButton *test2Button = new QPushButton(tr("Autolock never")); |
|
130 connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); |
|
131 connect(lockButton, SIGNAL(clicked()), this, SLOT(lockAction())); |
|
132 connect(unlockButton, SIGNAL(clicked()), this, SLOT(unlockAction())); |
|
133 connect(unguardButton, SIGNAL(clicked()), this, SLOT(unguardAction())); |
|
134 connect(test1Button, SIGNAL(clicked()), this, SLOT(test1Action())); |
|
135 connect(test2Button, SIGNAL(clicked()), this, SLOT(test2Action())); |
|
136 RDEBUG( "connect", 1 ); |
|
137 |
|
138 /* there's no use for this */ |
|
139 /* |
|
140 bool isService = XQServiceUtil::isService(); |
|
141 |
|
142 QString t = "SERVICEAPP:\n"; |
|
143 t = t + (isService ? " LAUNCHED AS SERVICE\n" : " LAUNCHED NORMALLY\n"); |
|
144 t = t + (XQServiceUtil::isEmbedded() ? " EMBEDDED\n" : " NOT EMBEDDED\n"); |
|
145 |
|
146 QStringList args = QApplication::arguments(); |
|
147 foreach (QString arg, args) |
|
148 { |
|
149 t += "cmdline arg=" + arg + "\n"; |
|
150 } |
|
151 |
|
152 QLabel *title = new QLabel(t); |
|
153 */ |
|
154 |
|
155 mLabel = new QLabel(""); |
|
156 mNumberEdit = new QLineEdit(""); |
|
157 |
|
158 QVBoxLayout *vl = new QVBoxLayout; |
|
159 |
|
160 vl->setMargin(0); |
|
161 vl->setSpacing(0); |
|
162 |
|
163 vl->addWidget(lockButton); |
|
164 vl->addWidget(unlockButton); |
|
165 vl->addWidget(unguardButton); |
|
166 vl->addWidget(quitButton); |
|
167 vl->addWidget(test1Button); |
|
168 vl->addWidget(test2Button); |
|
169 RDEBUG( "added test2Button", 1 ); |
|
170 |
|
171 mLabelIcon = new QToolButton; |
|
172 mLabelIcon->setIcon(QIcon(":/AutolockSrv_hbicon/qtg_large_device_lock.svg")); |
|
173 mLabelIcon->setIconSize(QSize(300,300)); |
|
174 |
|
175 vl->addWidget(mLabelIcon); |
|
176 RDEBUG( "added mLabelIcon", 1 ); |
|
177 |
|
178 /* vl->addItem(title); |
|
179 vl->addWidget(mLabel); |
|
180 vl->addWidget(mNumberEdit); |
|
181 */ |
|
182 setLayout(vl); |
|
183 |
|
184 #if defined(Q_WS_X11) || defined(Q_WS_WIN) |
|
185 setFixedSize(QSize(360,640)); // nHD |
|
186 #elif defined(Q_WS_S60) |
|
187 // showMaximized(); |
|
188 showFullScreen(); |
|
189 #endif |
|
190 mLabelIcon_visible=1; |
|
191 serviceKeyguard = new AutolockUserActivityService(); |
|
192 serviceDevicelock = new AutolockUserActivityService(); |
|
193 |
|
194 TInt lockValue = 0; |
|
195 TInt lightsTimeout = 0; |
|
196 CRepository* repository; |
|
197 TInt cRresult=0; |
|
198 |
|
199 iLockStatusPrev=ELockNotActive; |
|
200 iLockStatus=ELockNotActive; |
|
201 repository = CRepository::NewL(KCRUidSecuritySettings); |
|
202 cRresult = repository->Get(KSettingsAutolockStatus, lockValue); |
|
203 RDEBUG( "KSettingsAutolockStatus", KSettingsAutolockStatus ); |
|
204 RDEBUG( "cRresult", cRresult ); |
|
205 RDEBUG( "lockValue", lockValue ); |
|
206 iLockStatus = lockValue; |
|
207 // the settings says to lock |
|
208 delete repository; |
|
209 |
|
210 adjustInactivityTimers(0); |
|
211 |
|
212 repository = CRepository::NewL(KCRUidProfileEngine); |
|
213 cRresult = repository->Get(KProEngActiveProfile, lightsTimeout); |
|
214 delete repository; |
|
215 |
|
216 repository = CRepository::NewL(KCRUidLightSettings); |
|
217 cRresult = repository->Get(KDisplayLightsTimeout, lightsTimeout); |
|
218 delete repository; |
|
219 |
|
220 // TODO flip |
|
221 |
|
222 subscriberKSettingsAutolockStatus = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutolockStatus", this); |
|
223 connect(subscriberKSettingsAutolockStatus, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutolockStatusChanged())); |
|
224 subscriberKSettingsAutoLockTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutoLockTime", this); |
|
225 connect(subscriberKSettingsAutoLockTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutoLockTimeChanged())); |
|
226 subscriberKSettingsAutomaticKeyguardTime = new QValueSpaceSubscriber("/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime", this); |
|
227 connect(subscriberKSettingsAutomaticKeyguardTime, SIGNAL(contentsChanged()), this, SLOT(subscriberKSettingsAutomaticKeyguardTimeChanged())); |
|
228 subscriberKDisplayLightsTimeout = new QValueSpaceSubscriber("/KCRUidLightSettings/KDisplayLightsTimeout", this); |
|
229 connect(subscriberKDisplayLightsTimeout, SIGNAL(contentsChanged()), this, SLOT(subscriberKDisplayLightsTimeoutChanged())); |
|
230 subscriberKProEngActiveProfile = new QValueSpaceSubscriber("/KCRUidProfileEngine/KProEngActiveProfile", this); |
|
231 connect(subscriberKProEngActiveProfile, SIGNAL(contentsChanged()), this, SLOT(subscriberKProEngActiveProfileChanged())); |
|
232 |
|
233 |
|
234 TSecurityPolicy readPolicy( ECapabilityReadDeviceData ); |
|
235 TSecurityPolicy writePolicy( ECapabilityWriteDeviceData ); |
|
236 TInt ret = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, RProperty::EInt, readPolicy, writePolicy ); |
|
237 RDEBUG( "defined KSecurityUIsSecUIOriginatedQuery", ret ); |
|
238 ret = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, RProperty::EInt, readPolicy, writePolicy ); |
|
239 RDEBUG( "defined KSecurityUIsQueryRequestCancel", ret ); |
|
240 |
|
241 _LIT_SECURITY_POLICY_PASS(KReadPolicy); |
|
242 _LIT_SECURITY_POLICY_C1(KWritePolicy, ECapabilityWriteDeviceData); |
|
243 ret = RProperty::Define( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, RProperty::EInt, KReadPolicy, KWritePolicy); |
|
244 RDEBUG( "defined KCoreAppUIsAutolockStatus", ret ); |
|
245 |
|
246 ret = RProperty::Define(KPSUidAvkonDomain, KAknKeyguardStatus, RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass), KWritePolicy); |
|
247 RDEBUG( "defined KAknKeyguardStatus", ret ); |
|
248 |
|
249 // inactivity |
|
250 connect(serviceKeyguard, SIGNAL(active()), this, SLOT(activeKeyguard()) ); |
|
251 connect(serviceKeyguard, SIGNAL(notActive()), this, SLOT(notActiveKeyguard()) ); |
|
252 connect(serviceDevicelock, SIGNAL(active()), this, SLOT(activeDevicelock()) ); |
|
253 connect(serviceDevicelock, SIGNAL(notActive()), this, SLOT(notActiveDevicelock()) ); |
|
254 |
|
255 RWindowGroup& groupWin=CEikonEnv::Static()->RootWin(); |
|
256 RDEBUG( "got groupWin", 1 ); |
|
257 // TODO if I want to release, I should do: mKeyCaptureHandle = env->RootWin().CaptureKey(EKeyBackspace, 0, 0); |
|
258 groupWin.CaptureKey(EKeyBackspace,0,0); |
|
259 groupWin.CaptureKey(EKeyDeviceF,0,0); |
|
260 groupWin.CaptureKey(EKeyBell,0,0); |
|
261 groupWin.CaptureKey(EKeyTab,0,0); |
|
262 groupWin.CaptureKey(EKeyInsert,0,0); |
|
263 RDEBUG( "got mKeyCaptureHandle", 1 ); |
|
264 |
|
265 iSecQueryUiCreated=-1; |
|
266 iDeviceDialogCreated = -1; |
|
267 // TODO for now, always starts unlocked |
|
268 // TryChangeStatus(iLockStatus); |
|
269 TryChangeStatus(ELockNotActive); |
|
270 lower(); |
|
271 hide(); |
|
272 // not needed: new AutolockSrvService(this); |
|
273 } |
|
274 |
|
275 |
|
276 AutolockSrv::~AutolockSrv() |
|
277 { |
|
278 RDEBUG( "0", 0 ); |
|
279 delete mService; |
|
280 } |
|
281 |
|
282 void AutolockSrv::adjustInactivityTimers(int aReason) |
|
283 { |
|
284 RDEBUG( "aReason", aReason ); |
|
285 TInt keyguardTime = 0; |
|
286 TInt lockTime = 0; |
|
287 CRepository* repository; |
|
288 TInt cRresult = 0; |
|
289 |
|
290 repository = CRepository::NewL(KCRUidSecuritySettings); |
|
291 cRresult = repository->Get(KSettingsAutoLockTime, lockTime); |
|
292 RDEBUG( "KSettingsAutoLockTime", KSettingsAutoLockTime ); |
|
293 RDEBUG( "cRresult", cRresult ); |
|
294 RDEBUG( "lockTime", lockTime ); |
|
295 if(lockTime>0 && lockTime<1000) |
|
296 { |
|
297 serviceDevicelock->setInactivityPeriod(lockTime); |
|
298 } |
|
299 else |
|
300 { |
|
301 serviceDevicelock->setInactivityPeriod(12*31*24*60*60); |
|
302 } |
|
303 |
|
304 cRresult = repository->Get(KSettingsAutomaticKeyguardTime, keyguardTime); |
|
305 RDEBUG( "KSettingsAutomaticKeyguardTime", KSettingsAutomaticKeyguardTime ); |
|
306 RDEBUG( "cRresult", cRresult ); |
|
307 RDEBUG( "keyguardTime", keyguardTime ); |
|
308 if(keyguardTime>0 && keyguardTime<1000) |
|
309 { |
|
310 serviceKeyguard->setInactivityPeriod(keyguardTime); |
|
311 } |
|
312 else |
|
313 { |
|
314 serviceKeyguard->setInactivityPeriod(12*31*24*60*60); |
|
315 } |
|
316 delete repository; |
|
317 } |
|
318 void AutolockSrv::quit() |
|
319 { |
|
320 RDEBUG( "0", 0 ); |
|
321 qApp->quit(); |
|
322 } |
|
323 |
|
324 // from the button |
|
325 void AutolockSrv::unlockAction() |
|
326 { |
|
327 RDEBUG( "0", 0 ); |
|
328 TryChangeStatus(ELockAppDisableDevicelock); |
|
329 } |
|
330 |
|
331 void AutolockSrv::unguardAction() |
|
332 { |
|
333 RDEBUG( "0", 0 ); |
|
334 TryChangeStatus(ELockAppDisableKeyguard); |
|
335 } |
|
336 |
|
337 void AutolockSrv::test1Action() |
|
338 { |
|
339 RDEBUG( "Set(KSettingsAutoLockTime, 30000)", 30000 ); |
|
340 |
|
341 CRepository* repositorySet = CRepository::NewL(KCRUidSecuritySettings); |
|
342 repositorySet->Set(KSettingsAutoLockTime, 10); |
|
343 delete repositorySet; |
|
344 } |
|
345 |
|
346 void AutolockSrv::test2Action() |
|
347 { |
|
348 RDEBUG( "Set(KSettingsAutoLockTime, 20000)", 20000 ); |
|
349 |
|
350 CRepository* repositorySet = CRepository::NewL(KCRUidSecuritySettings); |
|
351 repositorySet->Set(KSettingsAutoLockTime, 0); |
|
352 delete repositorySet; |
|
353 } |
|
354 |
|
355 int AutolockSrv::AskValidSecCode(int aReason) |
|
356 { |
|
357 RDEBUG( "aReason", aReason ); |
|
358 RMobilePhone iPhone; // NULL in emulator |
|
359 |
|
360 #ifdef __WINS__1 |
|
361 return KErrNone; |
|
362 #endif |
|
363 |
|
364 TInt err( KErrGeneral); |
|
365 TBool validCode(EFalse); |
|
366 TInt thisTry( 0); |
|
367 RTelServer iTelServer; |
|
368 |
|
369 RMmCustomAPI iCustomPhone; |
|
370 while ( ( err = iTelServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer ) |
|
371 { |
|
372 User::After( KTimeBeforeRetryingServerConnection ); |
|
373 } |
|
374 err = iTelServer.LoadPhoneModule( KMmTsyModuleName ); |
|
375 RTelServer::TPhoneInfo PhoneInfo; |
|
376 RDEBUG( "err", err ); |
|
377 err = iTelServer.SetExtendedErrorGranularity( RTelServer::EErrorExtended ) ; |
|
378 RDEBUG( "err", err ); |
|
379 err = iTelServer.GetPhoneInfo( KPhoneIndex, PhoneInfo ) ; |
|
380 RDEBUG( "err", err ); |
|
381 err = iPhone.Open( iTelServer, PhoneInfo.iName ) ; |
|
382 RDEBUG( "err", err ); |
|
383 err = iCustomPhone.Open( iPhone ) ; |
|
384 RDEBUG( "err", err ); |
|
385 |
|
386 RDEBUG( "CSecurityHandler", 0 ); |
|
387 CSecurityHandler* handler = new(ELeave) CSecurityHandler(iPhone); |
|
388 if(aReason==ELockAppDisableDevicelock) |
|
389 { |
|
390 RDEBUG( "calling AskSecCodeInAutoLockL", 0 ); |
|
391 validCode = handler->AskSecCodeInAutoLockL(); // this returns true/false |
|
392 // TODO should this also do iPhone.SetLockSetting(status, lockType, lockChange); ??? |
|
393 } |
|
394 else if(aReason==ELockAppEnableDevicelock) |
|
395 { |
|
396 // check whether code is really needed |
|
397 RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice; |
|
398 RMobilePhone::TMobilePhoneLockInfoV1 lockInfo; |
|
399 RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo); |
|
400 RMobilePhone::TMobilePhoneLockSetting lockChange(RMobilePhone::ELockSetDisabled); |
|
401 TRequestStatus status = KRequestPending; |
|
402 TInt ret=KErrNone; |
|
403 RDEBUG( "GetLockInfo", 0 ); |
|
404 iPhone.GetLockInfo(status, lockType, lockInfoPkg); |
|
405 RDEBUG( "WaitForRequest", 0 ); |
|
406 User::WaitForRequest( status ); |
|
407 ret = status.Int(); |
|
408 RDEBUG( "WaitForRequest ret", ret ); |
|
409 #ifdef __WINS__ |
|
410 if(ret==KErrTimedOut) |
|
411 { |
|
412 ret = KErrNone; |
|
413 lockInfo.iSetting = RMobilePhone::ELockSetDisabled; // ask password only if there's no timeout. |
|
414 } |
|
415 #endif |
|
416 if(ret==KErrNone) |
|
417 { |
|
418 RDEBUG( "lockInfo.iSetting", lockInfo.iSetting ); |
|
419 RDEBUG( "RMobilePhone::ELockSetDisabled", RMobilePhone::ELockSetDisabled ); |
|
420 if(lockInfo.iSetting == RMobilePhone::ELockSetDisabled) // ask password only if there's no timeout |
|
421 { |
|
422 lockChange = RMobilePhone::ELockSetEnabled; |
|
423 RDEBUG( "SetLockSetting lockChange", lockChange ); |
|
424 #define OLD_METHODx |
|
425 #ifdef OLD_METHOD |
|
426 status = KRequestPending; |
|
427 RDEBUG( "SetLockSetting", 0 ); |
|
428 iPhone.SetLockSetting(status, lockType, lockChange); // ask for PassPhraseRequiredL |
|
429 RDEBUG( "WaitForRequestL", 0 ); |
|
430 User::WaitForRequest( status ); // TODO this waits 33 seconds in WINS and returns ffffffdf = KErrTimedOut |
|
431 ret = status.Int(); |
|
432 RDEBUG( "WaitForRequestL ret", ret ); |
|
433 #else |
|
434 RDEBUG( "! OLD_METHOD", 0 ); |
|
435 CWait *iWait = NULL; |
|
436 iWait = CWait::NewL(); |
|
437 iWait->SetRequestType(EMobilePhoneSetLockSetting); |
|
438 iPhone.SetLockSetting(iWait->iStatus, lockType, lockChange); // ask for PassPhraseRequiredL |
|
439 RDEBUG( "WaitForRequestL", 0 ); |
|
440 ret = iWait->WaitForRequestL(); |
|
441 RDEBUG( "WaitForRequestL ret", ret ); |
|
442 if(iWait) |
|
443 { |
|
444 RDEBUG( "IsActive", 0 ); |
|
445 if(iWait->IsActive()) |
|
446 { |
|
447 RDEBUG( "CancelAsyncRequest", 0 ); |
|
448 iPhone.CancelAsyncRequest(iWait->GetRequestType()); |
|
449 RDEBUG( "cancelled", 0 ); |
|
450 } |
|
451 } |
|
452 delete iWait; |
|
453 #endif |
|
454 |
|
455 RDEBUG( "WaitForRequestL ret", ret ); |
|
456 #ifdef __WINS__ |
|
457 if(ret==KErrTimedOut) |
|
458 ret = KErrNone; |
|
459 #endif |
|
460 if(ret==KErrNone) |
|
461 validCode = 1; |
|
462 else |
|
463 validCode = 0; |
|
464 } |
|
465 else |
|
466 validCode = 0x20; |
|
467 } |
|
468 else |
|
469 validCode = 0x21; |
|
470 |
|
471 /* Alternative way to ask for password |
|
472 RMobilePhone::TMobilePhoneSecurityEvent iEvent; |
|
473 TInt result = KErrNone; |
|
474 iEvent = RMobilePhone::EPhonePasswordRequired; |
|
475 RDEBUG( "calling HandleEventL", 0 ); |
|
476 handler->HandleEventL(iEvent, result); // this is supposed to wait |
|
477 validCode = false; |
|
478 if(result) |
|
479 validCode = true; |
|
480 RDEBUG( "result", result ); |
|
481 */ |
|
482 } |
|
483 // TODO this doesn't wait on WINS , so how do I get the Acceptation? |
|
484 RDEBUG( "validCode (true/false)", validCode ); |
|
485 if(validCode) |
|
486 return KErrNone; |
|
487 return KErrCancel; |
|
488 } |
|
489 |
|
490 void AutolockSrv::lockAction() |
|
491 { |
|
492 RDEBUG( "0", 0 ); |
|
493 |
|
494 XQSERVICE_DEBUG_PRINT("AutolockSrv::lockAction"); |
|
495 TryChangeStatus(ELockAppOfferDevicelock); |
|
496 |
|
497 } |
|
498 |
|
499 void AutolockSrv::handleAnswerDelivered() |
|
500 { |
|
501 RDEBUG( "This should never be called", 0 ); |
|
502 // quit(); |
|
503 |
|
504 } |
|
505 |
|
506 |
|
507 void AutolockSrv::endCall() |
|
508 { |
|
509 RDEBUG( "This should never be called", 0 ); |
|
510 //QVBoxLayout *vl = qobject_cast<QVBoxLayout *>(layout()) ; |
|
511 //vl->removeWidget(mEndCallButton); |
|
512 |
|
513 //XQServiceUtil::toBackground(true); |
|
514 } |
|
515 |
|
516 void AutolockSrv::setLabelNumber(QString label,QString number) |
|
517 { |
|
518 RDEBUG( "0", 0 ); |
|
519 mLabel->setText("mLabel=" + label); |
|
520 mNumberEdit->setText("mNumberEdit=" + number); |
|
521 } |
|
522 |
|
523 void AutolockSrv::DebugRequest(int aReason) |
|
524 { |
|
525 switch(aReason) |
|
526 { |
|
527 case ELockAppEnableKeyguard: |
|
528 RDEBUG( "ELockAppEnableKeyguard", aReason ); |
|
529 break; |
|
530 case ELockAppDisableKeyguard: |
|
531 RDEBUG( "ELockAppDisableKeyguard", aReason ); |
|
532 break; |
|
533 case ELockAppEnableDevicelock: |
|
534 RDEBUG( "ELockAppEnableDevicelock", aReason ); |
|
535 break; |
|
536 case ELockAppDisableDevicelock: |
|
537 RDEBUG( "ELockAppDisableDevicelock", aReason ); |
|
538 break; |
|
539 case ELockAppOfferKeyguard: |
|
540 RDEBUG( "ELockAppOfferKeyguard", aReason ); |
|
541 break; |
|
542 case ELockAppOfferDevicelock: |
|
543 RDEBUG( "ELockAppOfferDevicelock", aReason ); |
|
544 break; |
|
545 case ELockAppShowKeysLockedNote: |
|
546 RDEBUG( "ELockAppShowKeysLockedNote", aReason ); |
|
547 break; |
|
548 default: |
|
549 RDEBUG( "default", aReason ); |
|
550 break; |
|
551 } |
|
552 } |
|
553 void AutolockSrv::DebugStatus(int aReason) |
|
554 { |
|
555 switch(aReason) |
|
556 { |
|
557 case ELockNotActive: |
|
558 RDEBUG( "ELockNotActive", aReason ); |
|
559 break; |
|
560 case EKeyguardActive: |
|
561 RDEBUG( "EKeyguardActive", aReason ); |
|
562 break; |
|
563 case EDevicelockActive: |
|
564 RDEBUG( "EDevicelockActive", aReason ); |
|
565 break; |
|
566 default: |
|
567 RDEBUG( "default", aReason ); |
|
568 break; |
|
569 } |
|
570 } |
|
571 void AutolockSrv::DebugError(int aReason) |
|
572 { |
|
573 switch(aReason) |
|
574 { |
|
575 case KErrPermissionDenied: |
|
576 RDEBUG( "KErrPermissionDenied", aReason ); |
|
577 break; |
|
578 case KErrNone: |
|
579 RDEBUG( "KErrNone", aReason ); |
|
580 break; |
|
581 case KErrAlreadyExists: |
|
582 RDEBUG( "KErrAlreadyExists", aReason ); |
|
583 break; |
|
584 default: |
|
585 RDEBUG( "default", aReason ); |
|
586 break; |
|
587 } |
|
588 } |
|
589 |
|
590 int AutolockSrv::CheckIfLegal(int aReason) |
|
591 { |
|
592 RDEBUG( "aReason", aReason ); |
|
593 switch ( aReason ) |
|
594 { |
|
595 case ELockAppEnableKeyguard: |
|
596 { |
|
597 RDEBUG( "ELockAppEnableKeyguard iLockStatus", iLockStatus ); |
|
598 switch ( iLockStatus ) |
|
599 { |
|
600 case ELockNotActive: |
|
601 if ( 1==0 ) // !CKeyLockPolicyApi::KeyguardAllowed() ) |
|
602 return KErrPermissionDenied; |
|
603 else |
|
604 return KErrNone; |
|
605 case EKeyguardActive: |
|
606 return KErrAlreadyExists; |
|
607 case EDevicelockActive: |
|
608 return KErrPermissionDenied; |
|
609 } |
|
610 } |
|
611 break; |
|
612 case ELockAppDisableKeyguard: |
|
613 { |
|
614 RDEBUG( "ELockAppDisableKeyguard iLockStatus", iLockStatus ); |
|
615 switch ( iLockStatus ) |
|
616 { |
|
617 case ELockNotActive: |
|
618 return KErrAlreadyExists; |
|
619 case EKeyguardActive: |
|
620 return KErrNone; |
|
621 case EDevicelockActive: |
|
622 return KErrPermissionDenied; |
|
623 } |
|
624 } |
|
625 break; |
|
626 case ELockAppEnableDevicelock: |
|
627 { |
|
628 RDEBUG( "ELockAppEnableDevicelock iLockStatus", iLockStatus ); |
|
629 switch ( iLockStatus ) |
|
630 { |
|
631 case ELockNotActive: |
|
632 return KErrNone; |
|
633 case EKeyguardActive: |
|
634 return KErrNone; |
|
635 case EDevicelockActive: |
|
636 return KErrAlreadyExists; |
|
637 } |
|
638 } |
|
639 break; |
|
640 case ELockAppDisableDevicelock: |
|
641 { |
|
642 RDEBUG( "ELockAppDisableDevicelock iLockStatus", iLockStatus ); |
|
643 switch ( iLockStatus ) |
|
644 { |
|
645 case ELockNotActive: |
|
646 return KErrAlreadyExists; |
|
647 case EKeyguardActive: |
|
648 return KErrPermissionDenied; |
|
649 case EDevicelockActive: |
|
650 return KErrNone; |
|
651 } |
|
652 } |
|
653 break; |
|
654 case ELockAppOfferKeyguard: |
|
655 { |
|
656 RDEBUG( "ELockAppOfferKeyguard iLockStatus", iLockStatus ); |
|
657 switch ( iLockStatus ) |
|
658 { |
|
659 case ELockNotActive: |
|
660 return KErrNone; |
|
661 case EKeyguardActive: |
|
662 return KErrPermissionDenied; |
|
663 case EDevicelockActive: |
|
664 return KErrPermissionDenied; |
|
665 } |
|
666 } |
|
667 break; |
|
668 case ELockAppOfferDevicelock: |
|
669 { |
|
670 RDEBUG( "ELockAppOfferDevicelock iLockStatus", iLockStatus ); |
|
671 switch ( iLockStatus ) |
|
672 { |
|
673 case ELockNotActive: |
|
674 return KErrNone; |
|
675 case EKeyguardActive: |
|
676 return KErrNone; |
|
677 case EDevicelockActive: |
|
678 return KErrAlreadyExists; |
|
679 } |
|
680 } |
|
681 break; |
|
682 case ELockAppShowKeysLockedNote: |
|
683 { |
|
684 RDEBUG( "ELockAppShowKeysLockedNote iLockStatus", iLockStatus ); |
|
685 switch ( iLockStatus ) |
|
686 { |
|
687 case ELockNotActive: |
|
688 return KErrPermissionDenied; |
|
689 case EKeyguardActive: |
|
690 return KErrNone; |
|
691 case EDevicelockActive: |
|
692 return KErrPermissionDenied; |
|
693 } |
|
694 } |
|
695 break; |
|
696 default: |
|
697 { |
|
698 RDEBUG( "default iLockStatus", iLockStatus ); |
|
699 return KErrPermissionDenied; |
|
700 } |
|
701 // break; |
|
702 } // switch |
|
703 return KErrPermissionDenied; |
|
704 } |
|
705 |
|
706 int AutolockSrv::publishStatus(int aReason) |
|
707 { |
|
708 RDEBUG( "aReason", aReason ); |
|
709 const TUid KCRUidCoreApplicationUIsSysAp = { 0x101F8765 }; |
|
710 const TUint32 KSysApKeyguardActive = 0x00000001; |
|
711 CRepository* repositoryDevicelock; |
|
712 CRepository* repositoryKeyguard; |
|
713 repositoryDevicelock = CRepository::NewL(KCRUidSecuritySettings); |
|
714 repositoryKeyguard = CRepository::NewL(KCRUidSecuritySettings); |
|
715 TInt cRresult; |
|
716 |
|
717 if(1==1) |
|
718 { |
|
719 RDEBUG( "publishing", aReason ); |
|
720 if(aReason==ELockNotActive) |
|
721 { |
|
722 RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive); |
|
723 RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff); |
|
724 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0); // the settings remains. Only ISA changes, as well as the P&S |
|
725 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); |
|
726 } |
|
727 if(1==0) |
|
728 { |
|
729 if(aReason==EKeyguardActive) |
|
730 { |
|
731 RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardLocked); |
|
732 RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff); |
|
733 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 0); |
|
734 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 1); |
|
735 } |
|
736 else if(aReason>=EDevicelockActive) |
|
737 { |
|
738 RProperty::Set(KPSUidAvkonDomain, KAknKeyguardStatus, EKeyguardNotActive); // EKeyguardLocked sure? maybe EKeyguardNotActive ? |
|
739 RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked); |
|
740 // cRresult = repositoryDevicelock->Set(KSettingsAutolockStatus, 1); |
|
741 cRresult = repositoryKeyguard->Set(KSysApKeyguardActive, 0); // keyguard disabled, so that user can type and DeviceF can be captured |
|
742 } |
|
743 } |
|
744 } |
|
745 delete repositoryDevicelock; |
|
746 delete repositoryKeyguard; |
|
747 // this is the real point where everything is done. |
|
748 iLockStatusPrev = iLockStatus; |
|
749 iLockStatus = aReason; |
|
750 RDEBUG( "setting iLockStatus", iLockStatus ); |
|
751 return KErrNone; |
|
752 } |
|
753 /********************/ |
|
754 int AutolockSrv::showNoteIfRequested(int aReason) |
|
755 { |
|
756 RDEBUG( "aReason", aReason ); |
|
757 |
|
758 if(aReason==ELockNotActive) |
|
759 { |
|
760 if(iShowKeyguardNote==1) |
|
761 { |
|
762 HbDeviceMessageBox::information ("Keyguard deactivated"); |
|
763 } |
|
764 } |
|
765 else if(aReason==EKeyguardActive) |
|
766 { |
|
767 if(iShowKeyguardNote==1) |
|
768 { |
|
769 HbDeviceMessageBox::information ("Keyguard activated"); |
|
770 } |
|
771 } |
|
772 else if(aReason>=EDevicelockActive) // this doesn't happen, but we are prepared nevertheless |
|
773 { |
|
774 if(iShowKeyguardNote==1) |
|
775 { |
|
776 HbDeviceMessageBox::information ("Devicelock activated"); |
|
777 } |
|
778 } |
|
779 return KErrNone; |
|
780 } |
|
781 /***********************/ |
|
782 int AutolockSrv::TryChangeStatus(int aReason) |
|
783 { |
|
784 RDEBUG( "aReason", aReason ); |
|
785 int ret = aReason; |
|
786 int errorInProcess = KErrNone; |
|
787 DebugRequest(ret); |
|
788 |
|
789 switch(ret) |
|
790 { |
|
791 case ELockAppEnableKeyguard: // 1 |
|
792 { |
|
793 errorInProcess = CheckIfLegal(ret); |
|
794 DebugError(errorInProcess); |
|
795 if(errorInProcess==KErrNone) |
|
796 { |
|
797 setLabelIcon(EKeyguardActive); |
|
798 updateIndicator(EKeyguardActive); |
|
799 publishStatus(EKeyguardActive); |
|
800 showNoteIfRequested(EKeyguardActive); |
|
801 } |
|
802 } |
|
803 break; |
|
804 case ELockAppDisableKeyguard: // 2 |
|
805 { |
|
806 errorInProcess = CheckIfLegal(ret); |
|
807 DebugError(errorInProcess); |
|
808 if(errorInProcess==KErrNone) |
|
809 { |
|
810 setLabelIcon(ELockNotActive); |
|
811 updateIndicator(ELockNotActive); |
|
812 publishStatus(ELockNotActive); |
|
813 showNoteIfRequested(ELockNotActive); |
|
814 } |
|
815 } |
|
816 break; |
|
817 case ELockAppEnableDevicelock: // 3 |
|
818 { |
|
819 errorInProcess = CheckIfLegal(ret); |
|
820 DebugError(errorInProcess); |
|
821 if(errorInProcess==KErrNone) |
|
822 { |
|
823 if(!callerHasECapabilityWriteDeviceData) // check permissions for calling process, because doesn't AskValidSecCode |
|
824 errorInProcess=KErrPermissionDenied; |
|
825 DebugError(errorInProcess); |
|
826 } |
|
827 if(errorInProcess==KErrNone) |
|
828 { |
|
829 updateIndicator(EDevicelockActive); |
|
830 publishStatus(EDevicelockActive); |
|
831 setLabelIcon(EDevicelockActive); |
|
832 setLockDialog(aReason, 1); |
|
833 } |
|
834 // aParam1 is aReason : EDevicelockManual, EDevicelockRemote |
|
835 // this never shows a note |
|
836 } |
|
837 break; |
|
838 case ELockAppDisableDevicelock: // 4 |
|
839 { |
|
840 errorInProcess = CheckIfLegal(ret); |
|
841 DebugError(errorInProcess); |
|
842 if(errorInProcess==KErrNone) |
|
843 { |
|
844 if(!callerHasECapabilityWriteDeviceData) // check permissions for calling process, because doesn't AskValidSecCode |
|
845 errorInProcess=KErrPermissionDenied; |
|
846 DebugError(errorInProcess); |
|
847 } |
|
848 if(errorInProcess==KErrNone) |
|
849 { |
|
850 RDEBUG( " calling HbDeviceMessageBox::question", 0 ); |
|
851 bool value = HbDeviceMessageBox::question("Disable Lock?"); |
|
852 RDEBUG( "value", value ); |
|
853 if(!value) |
|
854 errorInProcess = KErrCancel; |
|
855 } |
|
856 if(errorInProcess==KErrNone) |
|
857 { |
|
858 setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it. |
|
859 RDEBUG( "calling AskValidSecCode", 0 ); |
|
860 errorInProcess=AskValidSecCode(ELockAppDisableDevicelock); |
|
861 RDEBUG( "errorInProcess", errorInProcess ); |
|
862 } |
|
863 if(errorInProcess==KErrNone) |
|
864 { |
|
865 setLabelIcon(ELockNotActive); |
|
866 updateIndicator(ELockNotActive); |
|
867 publishStatus(ELockNotActive); |
|
868 } |
|
869 if(errorInProcess!=KErrNone) |
|
870 { // re-lock. For example, if password is wrong |
|
871 setLockDialog(aReason, 1); |
|
872 } |
|
873 // this never shows a note |
|
874 } |
|
875 break; |
|
876 case ELockAppOfferKeyguard: // 5 |
|
877 { |
|
878 errorInProcess = CheckIfLegal(ret); |
|
879 DebugError(errorInProcess); |
|
880 if(errorInProcess==KErrNone) |
|
881 { |
|
882 bool value = HbDeviceMessageBox::question("Enable Keyguard?"); |
|
883 // TODO what about a nice icon? |
|
884 RDEBUG( "value", value ); |
|
885 if(!value) |
|
886 errorInProcess = KErrCancel; |
|
887 } |
|
888 if(errorInProcess==KErrNone) |
|
889 { |
|
890 errorInProcess = TryChangeStatus(ELockAppEnableKeyguard); |
|
891 } |
|
892 // this never shows a note |
|
893 } |
|
894 break; |
|
895 case ELockAppOfferDevicelock: // 6 |
|
896 { |
|
897 errorInProcess = CheckIfLegal(ret); |
|
898 DebugError(errorInProcess); |
|
899 setLockDialog(aReason, 0); // hide temporarilly because AskValidSecCode doesn't get in top of the Lock-icon. Thus, dismiss it. |
|
900 errorInProcess=AskValidSecCode(ELockAppEnableDevicelock); |
|
901 if(errorInProcess==KErrNone) |
|
902 { |
|
903 errorInProcess = TryChangeStatus(ELockAppEnableDevicelock); |
|
904 } |
|
905 // this never shows a note. Perhaps ELockAppEnableDevicelock does. |
|
906 } |
|
907 break; |
|
908 case ELockAppShowKeysLockedNote: |
|
909 { |
|
910 iShowKeyguardNote=1; // this is not sent as parameter, so we need to fake it: ON |
|
911 showNoteIfRequested(EKeyguardActive); |
|
912 } |
|
913 break; |
|
914 default: |
|
915 RDEBUG( "default", ret ); |
|
916 errorInProcess = KErrNotSupported; |
|
917 break; |
|
918 |
|
919 } |
|
920 return errorInProcess; |
|
921 } |
|
922 /**************************/ |
|
923 int AutolockSrv::setLockDialog(int aReason, int status) |
|
924 { |
|
925 RDEBUG( "aReason", aReason ); |
|
926 RDEBUG( "status", status ); |
|
927 RDEBUG( "iDeviceDialogCreated", iDeviceDialogCreated ); |
|
928 if(status==0) // hide |
|
929 { |
|
930 if(iDeviceDialogCreated>0) |
|
931 { |
|
932 iDeviceDialogCreated = 0; |
|
933 iDeviceDialog->cancel(); |
|
934 } |
|
935 } |
|
936 else if(status==1) // show |
|
937 { |
|
938 QVariantMap params; |
|
939 TBool err; |
|
940 #define ESecUiTypeDeviceLock 0x00100000 |
|
941 #define ESecUiTypeKeyguard 0x00200000 |
|
942 |
|
943 if(aReason==EKeyguardActive) |
|
944 params.insert("type", ESecUiTypeKeyguard); |
|
945 else if(aReason>=EDevicelockActive) |
|
946 params.insert("type", ESecUiTypeDeviceLock); |
|
947 else |
|
948 { |
|
949 RDEBUG( "error. status=1 but aReason", aReason ); |
|
950 } |
|
951 // no need for title. Icon should be explicit enough |
|
952 // params.insert("title", "Locked"); |
|
953 if(iDeviceDialogCreated<=0) |
|
954 { |
|
955 RDEBUG( "creating iDeviceDialog", 0 ); |
|
956 iDeviceDialog = new HbDeviceDialog(HbDeviceDialog::NoFlags, this); |
|
957 iDeviceDialogCreated = 1; |
|
958 } |
|
959 else |
|
960 { |
|
961 RDEBUG( "raising iDeviceDialog", 0 ); |
|
962 // confirm that dialog is present |
|
963 err = iDeviceDialog->error(); |
|
964 RDEBUG( "err", err ); |
|
965 iDeviceDialogCreated = 2; |
|
966 } |
|
967 const QString KSecQueryUiDeviceDialog("com.nokia.secuinotificationdialog/1.0"); |
|
968 RDEBUG( "pre show", aReason ); |
|
969 err = iDeviceDialog->show( KSecQueryUiDeviceDialog, params ); |
|
970 RDEBUG( "post show. err", err ); |
|
971 err = iDeviceDialog->error(); |
|
972 RDEBUG( "err", err ); |
|
973 } |
|
974 else |
|
975 { |
|
976 RDEBUG( "unknown status", status ); |
|
977 return KErrNotSupported; |
|
978 } |
|
979 return KErrNone; |
|
980 } |
|
981 void AutolockSrv::setLabelIcon(int aReason) |
|
982 { |
|
983 RDEBUG( "aReason", aReason ); |
|
984 |
|
985 if(aReason==ELockNotActive) |
|
986 { |
|
987 mLabelIcon->setVisible(false); |
|
988 setLockDialog(aReason, 0); // TODO isn't this done already at TryChangeStatus ??? |
|
989 lower(); |
|
990 hide(); |
|
991 } |
|
992 else if(aReason==EKeyguardActive) |
|
993 { |
|
994 mLabelIcon->setVisible(true); |
|
995 setLockDialog(aReason, 1); |
|
996 raise(); // not repaint(), not show() , not setVisible(true), not showFullScreen() , not ??? |
|
997 show(); |
|
998 } |
|
999 else if(aReason==EDevicelockActive) |
|
1000 { |
|
1001 mLabelIcon->setVisible(true); |
|
1002 raise(); |
|
1003 show(); |
|
1004 } |
|
1005 else |
|
1006 { |
|
1007 RDEBUG( "error: aReason", aReason ); |
|
1008 } |
|
1009 } |
|
1010 |
|
1011 int AutolockSrv::updateIndicator(int aReason) |
|
1012 { |
|
1013 RDEBUG( "aReason", aReason ); |
|
1014 QList<QVariant> list; |
|
1015 list.insert(0, 1); |
|
1016 list.insert(1, "aaa"); |
|
1017 list.insert(2, 2); |
|
1018 |
|
1019 HbIndicator indicator; |
|
1020 bool success; |
|
1021 if(aReason==ELockNotActive) |
|
1022 success = indicator.deactivate("com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0"); // maybe it's already deactivated. Not a problem |
|
1023 else if(aReason==EKeyguardActive) |
|
1024 success = indicator.activate("com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0"); |
|
1025 else if(aReason==EDevicelockActive) |
|
1026 success = indicator.activate("com.nokia.hb.indicator.autolocksrv.autolocksrv_8/1.0"); // same. We have just 1 indicator |
|
1027 else |
|
1028 success = 0; |
|
1029 RDEBUG( "success", success ); |
|
1030 return success; |
|
1031 } |
|
1032 |
|
1033 void AutolockSrv::activeKeyguard() |
|
1034 { |
|
1035 // activity while keyguarded. Nothing to do |
|
1036 RDEBUG( "0", 0 ); |
|
1037 } |
|
1038 |
|
1039 void AutolockSrv::notActiveKeyguard() |
|
1040 { |
|
1041 // inactivity. Keyguard should be activated |
|
1042 RDEBUG( "0", 0 ); |
|
1043 int ret = 0; |
|
1044 DebugStatus(iLockStatus); |
|
1045 if(iLockStatus==ELockNotActive) // not possible if it's keyguarded, or locked |
|
1046 { |
|
1047 ret = TryChangeStatus(ELockAppEnableKeyguard); |
|
1048 } |
|
1049 } |
|
1050 |
|
1051 void AutolockSrv::activeDevicelock() |
|
1052 { |
|
1053 RDEBUG( "0", 0 ); |
|
1054 } |
|
1055 |
|
1056 void AutolockSrv::notActiveDevicelock() |
|
1057 { |
|
1058 // inactivity. Devicelock should be activated |
|
1059 RDEBUG( "0", 0 ); |
|
1060 int ret = 0; |
|
1061 DebugStatus(iLockStatus); |
|
1062 if(iLockStatus==ELockNotActive || iLockStatus==EKeyguardActive ) // not possible if it's locked |
|
1063 { |
|
1064 ret = TryChangeStatus(ELockAppEnableDevicelock); |
|
1065 } |
|
1066 } |
|
1067 |
|
1068 // some key is pressed |
|
1069 bool AutolockSrv::event(QEvent *ev) |
|
1070 { |
|
1071 if (ev) |
|
1072 { |
|
1073 int isSwitchKey=0; |
|
1074 // on device, this doesn't seem to get the EKeyDeviceF key: only 1ffffff |
|
1075 if (ev->type() == QEvent::KeyPress){ |
|
1076 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); |
|
1077 qDebug() << QString("KeyPress:%1\n").arg(keyEvent->key(), 0, 16) ; |
|
1078 qDebug() << keyEvent->key(); |
|
1079 qDebug() << EKeyInsert; |
|
1080 qDebug() << (keyEvent->key()&0xFF); |
|
1081 qDebug() << (EKeyInsert&0xFF); |
|
1082 if((keyEvent->key()&0xFF) == (EKeyInsert&0xFF)) |
|
1083 { |
|
1084 qDebug() << "pressed EKeyInsert"; |
|
1085 // only reacts on release, not on press |
|
1086 isSwitchKey=1; |
|
1087 } |
|
1088 if((keyEvent->key()&0xFF) == (EKeyTab&0xFF)) |
|
1089 { |
|
1090 qDebug() << "pressed EKeyTab"; |
|
1091 } |
|
1092 if((keyEvent->key()&0xFF) == (EKeyDeviceF&0xFF)) |
|
1093 { |
|
1094 qDebug() << "pressed EKeyDeviceF"; |
|
1095 } |
|
1096 if( keyEvent->key() ==0x1ffffff ) |
|
1097 { |
|
1098 qDebug() << "pressed EKeyDeviceF-1ffffff"; |
|
1099 isSwitchKey=1; |
|
1100 } |
|
1101 } |
|
1102 else if (ev->type() == QEvent::KeyRelease) |
|
1103 { |
|
1104 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); |
|
1105 qDebug() << QString("KeyRelease:%1\n").arg(keyEvent->key(), 0, 16) ; |
|
1106 if( keyEvent->key() ==0x1ffffff ) |
|
1107 { |
|
1108 RDEBUG( "released EKeyDeviceF-1ffffff", 1 ); |
|
1109 // isSwitchKey=1; this should happen is pressed was not processed (hint: if it is/was in background) |
|
1110 } |
|
1111 } |
|
1112 RDEBUG( "isSwitchKey", isSwitchKey ); |
|
1113 if(isSwitchKey) |
|
1114 { |
|
1115 int ret; |
|
1116 DebugStatus(iLockStatus); |
|
1117 if(iLockStatus==ELockNotActive) |
|
1118 { |
|
1119 iShowKeyguardNote = 1; // note on enable keyguard |
|
1120 ret = TryChangeStatus(ELockAppEnableKeyguard); // this should not ask confirmation |
|
1121 } |
|
1122 else if(iLockStatus==EKeyguardActive) |
|
1123 { |
|
1124 iShowKeyguardNote = 1; // note on disable keyguard |
|
1125 ret = TryChangeStatus(ELockAppDisableKeyguard); |
|
1126 } |
|
1127 else if(iLockStatus==EDevicelockActive) |
|
1128 { |
|
1129 ret = TryChangeStatus(ELockAppDisableDevicelock); |
|
1130 } |
|
1131 } // isSwitchKey |
|
1132 } // ev |
|
1133 // Process if not done before. For example, redraw or quit |
|
1134 return QWidget::event(ev); |
|
1135 } |
|
1136 |
|
1137 bool AutolockSrv::eventFilter(QObject *o, QEvent *ev) |
|
1138 { |
|
1139 // this never happens |
|
1140 RDEBUG( "0", 0 ); |
|
1141 return QWidget::eventFilter(o, ev); |
|
1142 |
|
1143 } |
|
1144 |
|
1145 void AutolockSrv::subscriberKSettingsAutolockStatusChanged() |
|
1146 { |
|
1147 RDEBUG( "0", 0 ); |
|
1148 QVariant v = subscriberKSettingsAutolockStatus->value("/KCRUidSecuritySettings/KSettingsAutolockStatus"); |
|
1149 adjustInactivityTimers(KSettingsAutolockStatus); |
|
1150 qDebug() << "AutolockSrv::subscriberKSettingsAutolockStatusChanged" << v; |
|
1151 } |
|
1152 void AutolockSrv::subscriberKSettingsAutoLockTimeChanged() |
|
1153 { |
|
1154 RDEBUG( "0", 0 ); |
|
1155 QVariant v = subscriberKSettingsAutoLockTime->value("/KCRUidSecuritySettings/KSettingsAutoLockTime"); |
|
1156 adjustInactivityTimers(KSettingsAutoLockTime); |
|
1157 qDebug() << "AutolockSrv::subscriberKSettingsAutoLockTimeChanged" << v; |
|
1158 } |
|
1159 void AutolockSrv::subscriberKSettingsAutomaticKeyguardTimeChanged() |
|
1160 { |
|
1161 RDEBUG( "0", 0 ); |
|
1162 QVariant v = subscriberKSettingsAutomaticKeyguardTime->value("/KCRUidSecuritySettings/KSettingsAutomaticKeyguardTime"); |
|
1163 adjustInactivityTimers(KSettingsAutoLockTime); |
|
1164 qDebug() << "AutolockSrv::subscriberKSettingsAutomaticKeyguardTimeChanged" << v; |
|
1165 } |
|
1166 void AutolockSrv::subscriberKDisplayLightsTimeoutChanged() |
|
1167 { |
|
1168 RDEBUG( "0", 0 ); |
|
1169 QVariant v = subscriberKDisplayLightsTimeout->value("/KCRUidLightSettings/KDisplayLightsTimeout"); |
|
1170 // nothing to do |
|
1171 qDebug() << "AutolockSrv::subscriberKDisplayLightsTimeoutChanged" << v; |
|
1172 } |
|
1173 void AutolockSrv::subscriberKProEngActiveProfileChanged() |
|
1174 { |
|
1175 RDEBUG( "0", 0 ); |
|
1176 QVariant v = subscriberKProEngActiveProfile->value("/KCRUidProfileEngine/KProEngActiveProfile"); |
|
1177 // nothing to do |
|
1178 qDebug() << "AutolockSrv::subscriberKProEngActiveProfileChanged" << v; |
|
1179 } |
|
1180 |
|
1181 // ----------AutolockSrvService--------------- |
|
1182 |
|
1183 AutolockSrvService::AutolockSrvService(AutolockSrv* parent) |
|
1184 : XQServiceProvider(QLatin1String("com.nokia.services.AutolockSrv.AutolockSrv"),parent), |
|
1185 mAutolockSrv(parent), |
|
1186 mAsyncReqId(-1), |
|
1187 mAsyncAnswer(false) |
|
1188 { |
|
1189 RDEBUG( "0", 0 ); |
|
1190 publishAll(); |
|
1191 connect(this, SIGNAL(returnValueDelivered()), parent, SLOT(handleAnswerDelivered())); |
|
1192 } |
|
1193 |
|
1194 AutolockSrvService::~AutolockSrvService() |
|
1195 { |
|
1196 RDEBUG( "0", 0 ); |
|
1197 } |
|
1198 |
|
1199 void AutolockSrvService::complete(QString number) |
|
1200 { |
|
1201 RDEBUG( "0", 0 ); |
|
1202 if (mAsyncReqId == -1) |
|
1203 return; |
|
1204 XQSERVICE_DEBUG_PRINT("AutolockSrvService::complete"); |
|
1205 completeRequest(mAsyncReqId,number.toInt()); |
|
1206 } |
|
1207 |
|
1208 // gor API request |
|
1209 int AutolockSrvService::service(const QString& number, const QString& aParam1, const QString& aParam2 ) |
|
1210 { |
|
1211 RDEBUG( "0", 0 ); |
|
1212 qDebug() << "number=" << number; |
|
1213 qDebug() << "aParam1=" << aParam1; |
|
1214 qDebug() << "aParam2=" << aParam2; |
|
1215 mAsyncAnswer = false; |
|
1216 XQRequestInfo info = requestInfo(); |
|
1217 QSet<int> caps = info.clientCapabilities(); |
|
1218 |
|
1219 mAutolockSrv->callerHasECapabilityWriteDeviceData=0; |
|
1220 if(caps.contains(ECapabilityWriteDeviceData)) |
|
1221 { |
|
1222 RDEBUG( "callerHasECapabilityWriteDeviceData", ECapabilityWriteDeviceData ); |
|
1223 mAutolockSrv->callerHasECapabilityWriteDeviceData=1; |
|
1224 } |
|
1225 |
|
1226 QString label = "AutolockSrv::service:\n"; |
|
1227 label += QString("number=%1\n").arg(number); |
|
1228 |
|
1229 mNumber = number ; |
|
1230 mAutolockSrv->setLabelNumber(label, number); |
|
1231 int ret = 0; |
|
1232 ret = number.toInt(); |
|
1233 |
|
1234 mAutolockSrv->mParam1 = aParam1.toInt(); |
|
1235 mAutolockSrv->iShowKeyguardNote = aParam1.toInt(); |
|
1236 mAutolockSrv->mParam2 = aParam2.toInt(); |
|
1237 ret = mAutolockSrv->TryChangeStatus(ret); |
|
1238 RDEBUG( "ret", ret ); |
|
1239 return ret; |
|
1240 } |
|
1241 |
|
1242 void AutolockSrvService::handleClientDisconnect() |
|
1243 { |
|
1244 RDEBUG( "0", 0 ); |
|
1245 // Just quit service application if client ends |
|
1246 mAsyncAnswer = false; |
|
1247 RDEBUG( "0", 0 ); |
|
1248 // mAutolockSrv->quit(); |
|
1249 } |
|
1250 |
|
1251 /****************/ |
|
1252 CWait* CWait::NewL() |
|
1253 { |
|
1254 CWait* self = new(ELeave) CWait(); |
|
1255 CleanupStack::PushL(self); |
|
1256 self->ConstructL(); |
|
1257 CleanupStack::Pop(); |
|
1258 return self; |
|
1259 } |
|
1260 void CWait::ConstructL() |
|
1261 { |
|
1262 CActiveScheduler::Add(this); |
|
1263 } |
|
1264 CWait::CWait() : CActive(0) |
|
1265 { |
|
1266 } |
|
1267 CWait::~CWait() |
|
1268 { |
|
1269 Cancel(); |
|
1270 } |
|
1271 TInt CWait::WaitForRequestL() |
|
1272 { |
|
1273 SetActive(); |
|
1274 iWait.Start(); |
|
1275 return iStatus.Int(); |
|
1276 } |
|
1277 void CWait::RunL() |
|
1278 { |
|
1279 if(iWait.IsStarted()) |
|
1280 iWait.AsyncStop(); |
|
1281 } |
|
1282 void CWait::DoCancel() |
|
1283 { |
|
1284 if(iWait.IsStarted()) |
|
1285 iWait.AsyncStop(); |
|
1286 } |
|
1287 void CWait::SetRequestType(TInt aRequestType) |
|
1288 { |
|
1289 iRequestType = aRequestType; |
|
1290 } |
|
1291 TInt CWait::GetRequestType() |
|
1292 { |
|
1293 return iRequestType; |
|
1294 } |
|
1295 |