1 /* |
|
2 * Copyright (c) 2006 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 "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 <aknappui.h> |
|
20 #include <aknkeylock.h> |
|
21 #include <AknUtils.h> |
|
22 #include <activitymanager.h> |
|
23 #include <AknNotifierController.h> |
|
24 #include <centralrepository.h> |
|
25 #include <avkondomainpskeys.h> |
|
26 #include <e32property.h> |
|
27 #include <PSVariables.h> |
|
28 #include <startupdomainpskeys.h> |
|
29 #include <ctsydomainpskeys.h> |
|
30 #include <activeidle2domainpskeys.h> |
|
31 #include <coreapplicationuisdomainpskeys.h> |
|
32 #include <ScreensaverInternalPSKeys.h> |
|
33 #include <hwrmdomainpskeys.h> |
|
34 #include "AutoKeyguardCenRepI.h" |
|
35 #include "AutoKeyguardObserver.h" |
|
36 #include "AutolockPrivateCRKeys.h" |
|
37 #include "AutolockAppUiInterface.h" |
|
38 |
|
39 const TInt AutoKeyguardOff(60000); |
|
40 // Screensaver "On" status value |
|
41 const TInt KSsOn = 1; |
|
42 // Screensaver started fron idle status value |
|
43 const TInt KSsStartedFromIdle = 1; |
|
44 //Flip open |
|
45 const TInt KFlipOpen = 1; |
|
46 |
|
47 // ================= MEMBER FUNCTIONS ======================= |
|
48 // |
|
49 // ---------------------------------------------------------- |
|
50 // CAutoKeyguardObserver::NewL() |
|
51 // ---------------------------------------------------------- |
|
52 // |
|
53 |
|
54 CAutoKeyguardObserver* CAutoKeyguardObserver::NewL( MAutolockAppUiInterface* aAppUiI ) |
|
55 { |
|
56 #ifdef RD_AUTO_KEYGUARD |
|
57 #if defined(_DEBUG) |
|
58 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::NewL() BEGIN")); |
|
59 #endif |
|
60 CAutoKeyguardObserver* self = new (ELeave) CAutoKeyguardObserver( aAppUiI ); |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(self); |
|
63 CleanupStack::Pop(); //self |
|
64 #if defined(_DEBUG) |
|
65 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::NewL() END")); |
|
66 #endif |
|
67 return self; |
|
68 #else |
|
69 return NULL; |
|
70 #endif //RD_AUTO_KEYGUARD |
|
71 } |
|
72 // |
|
73 // ---------------------------------------------------------- |
|
74 // CAutoKeyguardObserver::CAutoKeyguardObserver() |
|
75 // C++ default constructor |
|
76 // ---------------------------------------------------------- |
|
77 // |
|
78 CAutoKeyguardObserver::CAutoKeyguardObserver( MAutolockAppUiInterface* aAppUiI ): |
|
79 iAppUiI( aAppUiI ) |
|
80 { |
|
81 } |
|
82 |
|
83 // |
|
84 // ---------------------------------------------------------- |
|
85 // CAutoKeyguardObserver::ConstructL() |
|
86 // Symbian OS default constructor |
|
87 // ---------------------------------------------------------- |
|
88 // |
|
89 void CAutoKeyguardObserver::ConstructL(CAutoKeyguardObserver* aObserver) |
|
90 { |
|
91 #ifdef RD_AUTO_KEYGUARD |
|
92 #if defined(_DEBUG) |
|
93 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::ConstructL() BEGIN")); |
|
94 #endif |
|
95 //Central Repository handler |
|
96 iCenRepI = CAutoKeyguardCenRepI::NewL(aObserver); |
|
97 // Activitymanager |
|
98 iActivityManager = CUserActivityManager::NewL(CActive::EPriorityStandard); |
|
99 StartActivityMonitoringL(); |
|
100 #if defined(_DEBUG) |
|
101 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::ConstructL() END")); |
|
102 #endif |
|
103 #else // !RD_AUTO_KEYGUARD |
|
104 iCenRepI = NULL; |
|
105 iActivityManager = NULL; |
|
106 #endif //RD_AUTO_KEYGUARD |
|
107 } |
|
108 // |
|
109 // ---------------------------------------------------------- |
|
110 // CAutoKeyguardObserver::StartActivityMonitoringL() |
|
111 // Start monitoring user activity |
|
112 // ---------------------------------------------------------- |
|
113 // |
|
114 void CAutoKeyguardObserver::StartActivityMonitoringL() |
|
115 { |
|
116 #ifdef RD_AUTO_KEYGUARD |
|
117 SetActivityManagerL(); |
|
118 #endif //RD_AUTO_KEYGUARD |
|
119 } |
|
120 |
|
121 // |
|
122 // ---------------------------------------------------------- |
|
123 // CAutoKeyguardObserver::StopActivityMonitoring() |
|
124 // Stop monitoring user activity |
|
125 // ---------------------------------------------------------- |
|
126 // |
|
127 void CAutoKeyguardObserver::StopActivityMonitoring() |
|
128 { |
|
129 #ifdef RD_AUTO_KEYGUARD |
|
130 CancelActivityManager(); |
|
131 #endif // RD_AUTO_KEYGUARD |
|
132 } |
|
133 |
|
134 // |
|
135 // ---------------------------------------------------------- |
|
136 // CAutoKeyguardObserver::SetActivityManagerL() |
|
137 // Initializes activymanager |
|
138 // ---------------------------------------------------------- |
|
139 // |
|
140 void CAutoKeyguardObserver::SetActivityManagerL() |
|
141 { |
|
142 #ifdef RD_AUTO_KEYGUARD |
|
143 #if defined(_DEBUG) |
|
144 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::SetActivityManagerL() BEGIN")); |
|
145 #endif |
|
146 if (AutoKeyguardTimeout() ) |
|
147 { |
|
148 #if defined(_DEBUG) |
|
149 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::SetActivityManagerL() ON: Start manager")); |
|
150 #endif |
|
151 iActivityManager->Start(AutoKeyguardTimeout(), TCallBack(HandleInactiveEventL,this), |
|
152 TCallBack(HandleActiveEventL,this)); |
|
153 } |
|
154 else |
|
155 { |
|
156 #if defined(_DEBUG) |
|
157 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::SetActivityManagerL() OFF: Start manager")); |
|
158 #endif |
|
159 iActivityManager->Start(AutoKeyguardOff, TCallBack(HandleInactiveEventL,this), |
|
160 TCallBack(HandleActiveEventL,this)); |
|
161 } |
|
162 |
|
163 #if defined(_DEBUG) |
|
164 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::SetActivityManagerL() END")); |
|
165 #endif |
|
166 #endif //RD_AUTO_KEYGUARD |
|
167 } |
|
168 // |
|
169 // ---------------------------------------------------------- |
|
170 // CAutoKeyguardObserver::CancelActivityManager() |
|
171 // UnInitializes activymanager |
|
172 // ---------------------------------------------------------- |
|
173 // |
|
174 void CAutoKeyguardObserver::CancelActivityManager() |
|
175 { |
|
176 #ifdef RD_AUTO_KEYGUARD |
|
177 if ( iActivityManager ) |
|
178 { |
|
179 iActivityManager->Cancel(); |
|
180 } |
|
181 #endif //RD_AUTO_KEYGUARD |
|
182 } |
|
183 // |
|
184 // ---------------------------------------------------------- |
|
185 // CAutoKeyguardObserver::~CAutoKeyguardObserver() |
|
186 // Destructor |
|
187 // ---------------------------------------------------------- |
|
188 // |
|
189 CAutoKeyguardObserver::~CAutoKeyguardObserver() |
|
190 { |
|
191 #ifdef RD_AUTO_KEYGUARD |
|
192 if(iCenRepI) |
|
193 delete iCenRepI; |
|
194 if(iActivityManager) |
|
195 { |
|
196 StopActivityMonitoring(); |
|
197 delete iActivityManager; |
|
198 iActivityManager = NULL; |
|
199 } |
|
200 #endif //RD_AUTO_KEYGUARD |
|
201 } |
|
202 // |
|
203 // ---------------------------------------------------------- |
|
204 // CAutoKeyguardObserver::AutoKeyguardTimeout() |
|
205 // Returns current AutoKeyguard period |
|
206 // ---------------------------------------------------------- |
|
207 // |
|
208 TInt CAutoKeyguardObserver::AutoKeyguardTimeout() |
|
209 { |
|
210 #ifdef RD_AUTO_KEYGUARD |
|
211 return iCenRepI->Timeout(); |
|
212 #else |
|
213 return 0; |
|
214 #endif //RD_AUTO_KEYGUARD |
|
215 } |
|
216 // |
|
217 // ---------------------------------------------------------- |
|
218 // CAutoKeyguardObserver::ResetInactivityTimeoutL() |
|
219 // Gets AutoKeyguard period and starts monitoring user activity |
|
220 // ---------------------------------------------------------- |
|
221 // |
|
222 void CAutoKeyguardObserver::ResetInactivityTimeout() |
|
223 { |
|
224 #ifdef RD_AUTO_KEYGUARD |
|
225 if (AutoKeyguardTimeout() ) |
|
226 { |
|
227 #if defined(_DEBUG) |
|
228 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::ResetInactivityTimeoutL() ON")); |
|
229 #endif |
|
230 iActivityManager->SetInactivityTimeout(AutoKeyguardTimeout()); |
|
231 } |
|
232 else |
|
233 { |
|
234 #if defined(_DEBUG) |
|
235 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::ResetInactivityTimeoutL() OFF")); |
|
236 #endif |
|
237 iActivityManager->SetInactivityTimeout(AutoKeyguardOff); |
|
238 } |
|
239 #endif //RD_AUTO_KEYGUARD |
|
240 } |
|
241 // |
|
242 // ---------------------------------------------------------- |
|
243 // CAutoKeyguardObserver::HandleActiveEventL() |
|
244 // Handles Active event. Called by ActivityManager |
|
245 // ---------------------------------------------------------- |
|
246 // |
|
247 TInt CAutoKeyguardObserver::HandleActiveEventL(TAny* /*aPtr*/) |
|
248 { |
|
249 return KErrNone; |
|
250 } |
|
251 |
|
252 // |
|
253 // ---------------------------------------------------------- |
|
254 // CAutoKeyguardObserver::HandleInactiveEventL() |
|
255 // Handles InActive event. Called by ActivityManager |
|
256 // ---------------------------------------------------------- |
|
257 // |
|
258 TInt CAutoKeyguardObserver::HandleInactiveEventL(TAny* aPtr) |
|
259 { |
|
260 #ifdef RD_AUTO_KEYGUARD |
|
261 #if defined(_DEBUG) |
|
262 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::HandleInactiveEventL() BEGIN")); |
|
263 #endif |
|
264 if ( STATIC_CAST(CAutoKeyguardObserver*, aPtr)->AutoKeyguardTimeout() ) |
|
265 { |
|
266 #if defined(_DEBUG) |
|
267 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::HandleInactiveEventL() Lock")); |
|
268 #endif |
|
269 STATIC_CAST(CAutoKeyguardObserver*, aPtr)->LockKeysL(); |
|
270 } |
|
271 #if defined(_DEBUG) |
|
272 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::HandleInactiveEventL() END")); |
|
273 #endif |
|
274 #endif //RD_AUTO_KEYGUARD |
|
275 return KErrNone; |
|
276 } |
|
277 |
|
278 // |
|
279 // ---------------------------------------------------------- |
|
280 // CAutoKeyguardObserver::LockKeysL() |
|
281 // Locks system |
|
282 // ---------------------------------------------------------- |
|
283 // |
|
284 void CAutoKeyguardObserver::LockKeysL() |
|
285 { |
|
286 #ifdef RD_AUTO_KEYGUARD |
|
287 #if defined(_DEBUG) |
|
288 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() BEGIN")); |
|
289 #endif |
|
290 CRepository* repository = CRepository::NewL(KCRUidAutolockConf); |
|
291 TInt keyguardConf(0); |
|
292 //Check local keyguard variation key |
|
293 repository->Get(KAutoKeyLockConf, keyguardConf); |
|
294 delete repository; |
|
295 if(keyguardConf & KAutoKeylockFeatureIdFlipOpenDisabled) |
|
296 { |
|
297 #if defined(_DEBUG) |
|
298 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Flip variation")); |
|
299 #endif |
|
300 TInt flipState(KFlipOpen); |
|
301 RProperty::Get(KPSUidHWRM, KHWRMFlipStatus, flipState); |
|
302 TInt lightStatus=EForcedLightsUninitialized; |
|
303 RProperty::Get(KPSUidCoreApplicationUIs,KLightsVTForcedLightsOn,lightStatus ); |
|
304 |
|
305 //If flip is open and feature flag is on. don't lock |
|
306 if(flipState == KFlipOpen || lightStatus == EForcedLightsOn) |
|
307 { |
|
308 #if defined(_DEBUG) |
|
309 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Flip open")); |
|
310 #endif |
|
311 return; |
|
312 } |
|
313 |
|
314 } |
|
315 |
|
316 { // REQ 414-5466 Prevention of device lock in context of Hands Free Voice UI |
|
317 TInt vuiValue = 0; |
|
318 TUid KHFVuiModePSUid = { 0x102818E7 }; |
|
319 enum THFVuiModePSKeys |
|
320 { |
|
321 EHFVuiPSModeId = 1000 |
|
322 }; |
|
323 TInt tRet = RProperty::Get(KHFVuiModePSUid, EHFVuiPSModeId, vuiValue); // also 0 if can't get because permissions or because doesn't exists |
|
324 #if defined(_DEBUG) |
|
325 RDebug::Printf( "%s %s (%u) gatting KHFVuiModePSUid+EHFVuiPSModeId=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, tRet ); |
|
326 RDebug::Printf( "%s %s (%u) vuiValue=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, vuiValue ); |
|
327 #endif |
|
328 if(vuiValue) |
|
329 { |
|
330 #if defined(_DEBUG) |
|
331 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Voice functions active. No locking possible.")); |
|
332 #endif |
|
333 return; |
|
334 } |
|
335 } |
|
336 |
|
337 TInt value = 0; |
|
338 TBool keylockOn = EFalse; |
|
339 TBool autolockOn = EFalse; |
|
340 TBool idle = EFalse; |
|
341 TInt callState = EPSCTsyCallStateNone; |
|
342 TBool okToLock = EFalse; |
|
343 TBool screenSaverOn = EFalse; |
|
344 TBool screenSaverStertedFromIdle = EFalse; |
|
345 TBool startupOver = EFalse; |
|
346 TBool codeQueryOpen = EFalse; |
|
347 //Get keyguard status |
|
348 RProperty::Get(KPSUidAvkonDomain, KAknKeyguardStatus, value); |
|
349 keylockOn = (value == EKeyguardLocked); |
|
350 //Get call state |
|
351 RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callState); |
|
352 |
|
353 //See whether we are in idle |
|
354 value = 0; |
|
355 RProperty::Get(KPSUidAiInformation, KActiveIdleState, value); |
|
356 idle = (value == EPSAiForeground); |
|
357 idle = ETrue; // don't care about idle state. Phone should autolock on any UI, not only HomeSreeen. |
|
358 |
|
359 value = 0; |
|
360 RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, value); |
|
361 autolockOn = (value > EAutolockOff); |
|
362 |
|
363 value = 0; |
|
364 RProperty::Get(KPSUidScreenSaver, KScreenSaverOn, value); |
|
365 screenSaverOn = (value == KSsOn); |
|
366 |
|
367 value = 0; |
|
368 RProperty::Get(KPSUidScreenSaver, KScreenSaverActivatedFromIdle, value); |
|
369 screenSaverStertedFromIdle = (value == KSsStartedFromIdle); |
|
370 |
|
371 // See if SIM is accepted |
|
372 if(idle) |
|
373 { |
|
374 value = 0; |
|
375 RProperty::Get(KPSUidStartup, KPSSimStatus, value); |
|
376 // automatic lock can't get enabled if SIM-locked. |
|
377 if(value == ESimNotReady) |
|
378 idle = EFalse; |
|
379 #if defined(_DEBUG) |
|
380 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() KPSSimStatus state: %d"), value); |
|
381 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() ESimUsable: %d"), ESimUsable); |
|
382 #endif |
|
383 } |
|
384 |
|
385 //See if all the startup related queries and graphics has been displayed |
|
386 value = 0; |
|
387 RProperty::Get(KPSUidStartup, KPSStartupUiPhase, value); |
|
388 startupOver = (value == EStartupUiPhaseAllDone); |
|
389 |
|
390 #if defined(_DEBUG) |
|
391 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() startupOver: %d"), startupOver); |
|
392 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Startup state: %d"), value); |
|
393 #endif |
|
394 //See if the lock code query is open |
|
395 codeQueryOpen = iAppUiI->DeviceLockQueryStatus(); |
|
396 #if defined(_DEBUG) |
|
397 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() codeQueryOpen: %d"), codeQueryOpen); |
|
398 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() autolockOn: %d"), autolockOn); |
|
399 #endif |
|
400 if (startupOver) |
|
401 { |
|
402 // If lock code query is open and device lock is on, cancel the query. |
|
403 // AppUi will enable keylock when the query is cancelled |
|
404 if (autolockOn && codeQueryOpen) |
|
405 { |
|
406 #if defined(_DEBUG) |
|
407 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Query open, cancel it")); |
|
408 #endif |
|
409 iAppUiI->CancelDeviceLockQuery(); |
|
410 return; |
|
411 } |
|
412 // If keylock is already ON, there is a ongoing call, |
|
413 // autolock is already ON or phone is not in idle, don't lock. |
|
414 if (keylockOn || (callState > EPSCTsyCallStateNone) || autolockOn || !idle) |
|
415 { |
|
416 #if defined(_DEBUG) |
|
417 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Don't lock")); |
|
418 RDebug::Print(_L("(AUTOLOCK)keylockstatus: %d"), keylockOn); |
|
419 RDebug::Print(_L("(AUTOLOCK)callstate: %d"), callState); |
|
420 RDebug::Print(_L("(AUTOLOCK)autolockstate: %d"), autolockOn); |
|
421 RDebug::Print(_L("(AUTOLOCK)idlestate: %d"), idle); |
|
422 RDebug::Print(_L("(AUTOLOCK)screenSaverOn: %d"), screenSaverOn); |
|
423 RDebug::Print(_L("(AUTOLOCK)screenSaverStertedFromIdle: %d"), screenSaverStertedFromIdle); |
|
424 #endif |
|
425 //If screensaver is on, idle does not have foreground. If Screensaver was started from Idle, lock keys. |
|
426 if(!idle && screenSaverOn && screenSaverStertedFromIdle && (callState <= EPSCTsyCallStateNone)) |
|
427 okToLock = ETrue; |
|
428 else |
|
429 okToLock = EFalse; |
|
430 } |
|
431 else //Otherwise there's no problem... |
|
432 okToLock = ETrue; |
|
433 } |
|
434 |
|
435 |
|
436 if (okToLock) |
|
437 { |
|
438 #if defined(_DEBUG) |
|
439 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Lock")); |
|
440 RDebug::Print(_L("(AUTOLOCK)keylockstatus: %d"), keylockOn); |
|
441 RDebug::Print(_L("(AUTOLOCK)callstate: %d"), callState); |
|
442 RDebug::Print(_L("(AUTOLOCK)autolockstate: %d"), autolockOn); |
|
443 RDebug::Print(_L("(AUTOLOCK)idlestate: %d"), idle); |
|
444 RDebug::Print(_L("(AUTOLOCK)screenSaverOn: %d"), screenSaverOn); |
|
445 RDebug::Print(_L("(AUTOLOCK)screenSaverStertedFromIdle: %d"), screenSaverStertedFromIdle); |
|
446 #endif |
|
447 //Tell keylock to lock itself. |
|
448 RAknKeyLock keylock; |
|
449 if ( keylock.Connect() == KErrNone ) |
|
450 { |
|
451 #if defined(_DEBUG) |
|
452 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() Connect OK")); |
|
453 #endif |
|
454 if(AknLayoutUtils::PenEnabled()) |
|
455 keylock.EnableWithoutNote(); //Enable without note |
|
456 else |
|
457 keylock.EnableKeyLock(); |
|
458 keylock.Close(); |
|
459 } |
|
460 } |
|
461 #if defined(_DEBUG) |
|
462 RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() END")); |
|
463 #endif |
|
464 #endif //RD_AUTO_KEYGUARD |
|
465 } |
|
466 |
|
467 |
|
468 // END OF FILE |
|