|
1 /* |
|
2 * Copyright (c) 2007 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: Keylock policy Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "keylockpolicyapiimpl.h" |
|
20 #include <LockDomainCRKeys.h> |
|
21 |
|
22 #include <centralrepository.h> |
|
23 #include "gendebug.h" |
|
24 |
|
25 const TUint32 KModeShift = 16; |
|
26 const TUint32 KTypeShift = 12; |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // Standard two-phased construction |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CKeyLockPolicyApiImpl* CKeyLockPolicyApiImpl::NewL( TLockPolicyType aType ) |
|
33 { |
|
34 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::NewL()" ) ); |
|
35 CKeyLockPolicyApiImpl *self = new ( ELeave ) CKeyLockPolicyApiImpl( aType ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL( ); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Destructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CKeyLockPolicyApiImpl::~CKeyLockPolicyApiImpl( ) |
|
47 { |
|
48 // notifier listeners are stopped |
|
49 if ( iAllowNotif ) |
|
50 { |
|
51 iAllowNotif->StopListening( ); |
|
52 } |
|
53 if ( iModeNotif ) |
|
54 { |
|
55 iModeNotif->StopListening( ); |
|
56 } |
|
57 |
|
58 // keys are removed from the arrays |
|
59 iPrimaryKeys.Reset( ); |
|
60 iSecondaryKeys.Reset( ); |
|
61 iWaitingKeys.Reset( ); |
|
62 |
|
63 // timer between key presses is cancelled |
|
64 if ( iKeyLockTimer ) |
|
65 { |
|
66 iKeyLockTimer->Cancel( ); |
|
67 } |
|
68 |
|
69 // childs are destroyed |
|
70 delete iKeyLockTimer; |
|
71 delete iAllowNotif; |
|
72 delete iModeNotif; |
|
73 delete iRep; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Returns true if the policy initialization has been successful. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 TBool CKeyLockPolicyApiImpl::HasConfiguration( ) |
|
81 { |
|
82 return iInitialised; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Set the central repository key to allow keyguard |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 TInt CKeyLockPolicyApiImpl::EnableKeyguardFeature( ) |
|
90 { |
|
91 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::EnableKeyguardFeature()" ) ); |
|
92 TInt err( KErrUnknown); |
|
93 |
|
94 if ( iRep ) |
|
95 { |
|
96 err = iRep->Set( KLockKeyguardAllow, ETrue ); |
|
97 } |
|
98 |
|
99 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::EnableKeyguardFeature()" ) ); |
|
100 return err; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Set the central repository key to disable keyguard |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CKeyLockPolicyApiImpl::DisableKeyguardFeature( ) |
|
108 { |
|
109 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::DisableKeyguardFeature()" ) ); |
|
110 TInt err( KErrUnknown); |
|
111 |
|
112 if ( iRep ) |
|
113 { |
|
114 err = iRep->Set( KLockKeyguardAllow, EFalse ); |
|
115 } |
|
116 |
|
117 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::DisableKeyguardFeature()" ) ); |
|
118 return err; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // Return true if keyguard feature is allowed |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 TBool CKeyLockPolicyApiImpl::KeyguardAllowed( ) |
|
126 { |
|
127 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::KeyguardAllowed()" ) ); |
|
128 TBool ret( ETrue); |
|
129 |
|
130 TInt tmp( 0); |
|
131 CRepository* rep= NULL; |
|
132 TRAPD( err, rep = CRepository::NewL( KCRUidLockConf ) ) |
|
133 if ( err || !rep ) |
|
134 { |
|
135 ret = ETrue; |
|
136 } |
|
137 else |
|
138 if ( rep && rep->Get( KLockKeyguardAllow, tmp )== KErrNone ) |
|
139 { |
|
140 if ( tmp ) |
|
141 { |
|
142 ret = ETrue; |
|
143 } |
|
144 else |
|
145 { |
|
146 ret = EFalse; |
|
147 } |
|
148 } |
|
149 delete rep; |
|
150 |
|
151 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::KeyguardAllowed()" ) ); |
|
152 return ret; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Add new key combination to the selected policy type+mode combination |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CKeyLockPolicyApiImpl::AddKeyCombination( TUint32 aPrimaryKey, TUint32 aSecondaryKey ) |
|
160 { |
|
161 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::AddKeyCombination()" ) ); |
|
162 TInt err( KErrNone); |
|
163 |
|
164 // mode zero means no policies are defined |
|
165 // and the implementation needs the repository |
|
166 if ( iMode && iRep ) |
|
167 { |
|
168 TInt putindex( 0); |
|
169 err = GetNewKeyCombinationIndex( putindex ); |
|
170 err = SetKeyCombination( aPrimaryKey, aSecondaryKey, putindex ); |
|
171 } |
|
172 else |
|
173 { |
|
174 err = KErrUnknown; |
|
175 } |
|
176 |
|
177 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::AddKeyCombination()" ) ); |
|
178 return err; |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // Removes a key set defined in the selected policy type+mode combination |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CKeyLockPolicyApiImpl::RemoveKeyCombination( TUint32 aPrimaryKey, TUint32 aSecondaryKey ) |
|
186 { |
|
187 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::RemoveKeyCombination()" ) ); |
|
188 TInt err( KErrNone); |
|
189 |
|
190 // the implementation needs the repository |
|
191 if ( iMode && iRep ) |
|
192 { |
|
193 TInt removeindex( 0); |
|
194 err = FindKeyCombinationIndex( aPrimaryKey, aSecondaryKey, removeindex ); |
|
195 if ( err == KErrNone ) |
|
196 { |
|
197 TInt lastindex( 0); |
|
198 TUint32 tmpprimary( 0), tmpsecondary( 0); |
|
199 |
|
200 // find out the index of the last key set |
|
201 err = GetNewKeyCombinationIndex( lastindex ); |
|
202 lastindex--; |
|
203 |
|
204 // collect the keys of the last existing key set |
|
205 err = GetKeyCombination( lastindex, tmpprimary, tmpsecondary ); |
|
206 if ( err == KErrNone ) |
|
207 { |
|
208 err = SetKeyCombination( tmpprimary, tmpsecondary, removeindex ); |
|
209 if ( err == KErrNone ) |
|
210 { |
|
211 // delete the already copied last key set |
|
212 iRep->Delete( iMask | KLockFirstPrimaryKey + lastindex ); |
|
213 iRep->Delete( iMask | KLockFirstSecondaryKey + lastindex ); |
|
214 } |
|
215 } |
|
216 } |
|
217 else |
|
218 { |
|
219 // if err != KErrNone either keys were not found or |
|
220 // there are problems in the repository |
|
221 } |
|
222 } |
|
223 else |
|
224 { |
|
225 err = KErrUnknown; |
|
226 } |
|
227 |
|
228 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::RemoveKeyCombination()" ) ); |
|
229 return err; |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // Finds the index of the given combination. |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 TInt CKeyLockPolicyApiImpl::FindKeyCombinationIndex(TUint32 aPrimaryKey, TUint32 aSecondaryKey, |
|
237 TInt &aIndex ) |
|
238 { |
|
239 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::FindKeyCombinationIndex()" ) ); |
|
240 TInt err( KErrNone); |
|
241 |
|
242 if ( iMode && iRep ) |
|
243 { |
|
244 TInt index( 0), tmpprimary( 0), tmpsecondary( 0); |
|
245 |
|
246 // go trough the keys until you find the primary key and secondary key |
|
247 while (err == KErrNone && tmpprimary != aPrimaryKey && tmpsecondary != aSecondaryKey ) |
|
248 { |
|
249 err = iRep->Get( iMask | KLockFirstPrimaryKey + index, tmpprimary ); |
|
250 if ( err == KErrNone ) |
|
251 { |
|
252 err = iRep->Get( iMask | KLockFirstSecondaryKey + index, tmpsecondary ); |
|
253 } |
|
254 index++; |
|
255 } |
|
256 |
|
257 // if we found it for sure |
|
258 if ( tmpprimary == aPrimaryKey && tmpsecondary == aSecondaryKey ) |
|
259 { |
|
260 aIndex = index - 1; |
|
261 err = KErrNone; |
|
262 } |
|
263 } |
|
264 else |
|
265 { |
|
266 err = KErrUnknown; |
|
267 } |
|
268 |
|
269 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::FindKeyCombinationIndex()" ) ); |
|
270 return err; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // Finds the index for a new combination (last one + 1). |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 TInt CKeyLockPolicyApiImpl::GetNewKeyCombinationIndex(TInt &aIndex ) |
|
278 { |
|
279 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::GetNewKeyCombinationIndex()" ) ); |
|
280 TInt err( KErrNone); |
|
281 |
|
282 if ( iMode && iRep ) |
|
283 { |
|
284 TInt index( 0), tmpvar( 0); |
|
285 while ( iRep->Get( iMask | KLockFirstPrimaryKey + index, tmpvar )== KErrNone ) |
|
286 { |
|
287 index++; |
|
288 }; |
|
289 |
|
290 // set the return value |
|
291 aIndex = index; |
|
292 } |
|
293 else |
|
294 { |
|
295 err = KErrUnknown; |
|
296 } |
|
297 |
|
298 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::GetNewKeyCombinationIndex()" ) ); |
|
299 return err; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // Sets a combination at the given index. |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 TInt CKeyLockPolicyApiImpl::SetKeyCombination(TUint32 aPrimaryKey, TUint32 aSecondaryKey, |
|
307 TInt aIndex ) |
|
308 { |
|
309 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::SetKeyCombination()" ) ); |
|
310 TInt err( KErrNone); |
|
311 |
|
312 if ( iMode && iRep ) |
|
313 { |
|
314 // set the last key set over the removed key combination |
|
315 err = iRep->Set( iMask | KLockFirstPrimaryKey + aIndex, (TInt) aPrimaryKey ); |
|
316 if ( err == KErrNone ) |
|
317 { |
|
318 err = iRep->Set( iMask | KLockFirstSecondaryKey + aIndex, (TInt) aSecondaryKey ); |
|
319 } |
|
320 } |
|
321 else |
|
322 { |
|
323 err = KErrUnknown; |
|
324 } |
|
325 |
|
326 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::SetKeyCombination()" ) ); |
|
327 return err; |
|
328 } |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // Returns a key combination from spesified index |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 TInt CKeyLockPolicyApiImpl::GetKeyCombination( TInt aIndex, TUint32 &aPrimaryKey, |
|
335 TUint32 &aSecondaryKey ) |
|
336 { |
|
337 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::GetKeyCombination()" ) ); |
|
338 TInt err( KErrNone); |
|
339 |
|
340 // the implementation needs the repository |
|
341 if ( iMode && iRep ) |
|
342 { |
|
343 TInt tmppri( 0), tmpsec( 0); |
|
344 |
|
345 // collect the primary key from the index |
|
346 err = iRep->Get( iMask | KLockFirstPrimaryKey + aIndex, tmppri ); |
|
347 if ( err == KErrNone ) |
|
348 { |
|
349 // devicelock query needs only one key |
|
350 if ( iType == EPolicyDevicelockQuery ) |
|
351 { |
|
352 tmpsec = 0; |
|
353 } |
|
354 else |
|
355 { |
|
356 // collect the secondary key from the index |
|
357 err = iRep->Get( iMask | ( KLockFirstSecondaryKey + aIndex ), tmpsec ); |
|
358 } |
|
359 |
|
360 if ( err == KErrNone ) |
|
361 { |
|
362 TraceDump( INFO_LEVEL, ( _L( "CKeyLockPolicyApiImpl::GetKeyCombination(): key combination: 0x%x, 0x%x" ), tmppri, tmpsec ) ); |
|
363 } |
|
364 else |
|
365 { |
|
366 // if err != KErrNone either the secondary key was |
|
367 // not found or there are problems in the repository |
|
368 } |
|
369 |
|
370 aPrimaryKey = TUint32( tmppri ); |
|
371 aSecondaryKey = TUint32( tmpsec ); |
|
372 } |
|
373 else |
|
374 { |
|
375 // if err != KErrNone either the primary key was |
|
376 // not found or there are problems in the repository |
|
377 } |
|
378 } |
|
379 else |
|
380 { |
|
381 err = KErrUnknown; |
|
382 } |
|
383 |
|
384 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::GetKeyCombination()" ) ); |
|
385 return err; |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // Clear all key combinations from the selected policy type+mode combination |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 TInt CKeyLockPolicyApiImpl::ClearKeycombinations( ) |
|
393 { |
|
394 TraceDump( INFO_LEVEL, _L( "ENTER: CKeyLockPolicyApiImpl::ClearKeycombinations()" ) ); |
|
395 TInt err( KErrNone); |
|
396 |
|
397 // the implementation needs the repository |
|
398 if ( iMode && iRep ) |
|
399 { |
|
400 TInt index( 0), tmpvar( 0); |
|
401 // go trough the primary keys and delete them |
|
402 while ( iRep->Get( iMask | KLockFirstPrimaryKey + index, tmpvar )== KErrNone ) |
|
403 { |
|
404 err = iRep->Delete( iMask | KLockFirstPrimaryKey + index ); |
|
405 index++; |
|
406 } |
|
407 |
|
408 index = 0; |
|
409 // go trough the secondary keys and delete them |
|
410 while ( iRep->Get( iMask | KLockFirstSecondaryKey + index, tmpvar )== KErrNone ) |
|
411 { |
|
412 err = iRep->Delete( iMask | KLockFirstSecondaryKey + index ); |
|
413 index++; |
|
414 } |
|
415 } |
|
416 else |
|
417 { |
|
418 err = KErrUnknown; |
|
419 } |
|
420 |
|
421 TraceDump( INFO_LEVEL, _L( "EXIT : CKeyLockPolicyApiImpl::ClearKeycombinations()" ) ); |
|
422 return err; |
|
423 } |
|
424 |
|
425 // --------------------------------------------------------------------------- |
|
426 // Receives keys and checks whether they match any primary+secondary key combination |
|
427 // --------------------------------------------------------------------------- |
|
428 // |
|
429 TBool CKeyLockPolicyApiImpl::HandleKeyEventL( const TKeyEvent& aKeyEvent, const TEventCode aType ) |
|
430 { |
|
431 TBool matchFound( EFalse); |
|
432 // keylock policy only handles key events of type EEventKeyDown |
|
433 TEventCode type( EEventKeyDown); |
|
434 |
|
435 if ( aType == type ) |
|
436 { |
|
437 // configuration keys in general are not handled if the policy has not been not initialized |
|
438 // configuration keys for enabling are not handled if keyguard feature is disabled |
|
439 if ( iInitialised && ( iAllowed || iType != EPolicyActivateKeyguard ) ) |
|
440 { |
|
441 |
|
442 // if primary key has already been pressed check if the key matches |
|
443 // the subsequent secondary key stored in the waiting keys array |
|
444 if ( iPrimaryKeyDown ) |
|
445 { |
|
446 TraceDump( INFO_LEVEL, ( _L( "CKeyLockPolicyApiImpl::HandleKeyEventL() : iPrimaryKeyDown, Mode: 0x%x" ), iMode ) ); |
|
447 if ( iWaitingKeys.Find( aKeyEvent.iScanCode )!= KErrNotFound ) |
|
448 { |
|
449 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::HandleKeyEventL() : Secondary key Pressed" ) ); |
|
450 matchFound = ETrue; |
|
451 } |
|
452 // cancel the timer after secondary key candidate has been pressed |
|
453 iKeyLockTimer->Cancel( ); |
|
454 iWaitingKeys.Reset( ); |
|
455 } |
|
456 |
|
457 // if the received key did not provide a match for secondary keys |
|
458 // the primary key match is investigated |
|
459 if ( !matchFound ) |
|
460 { |
|
461 // check if the key matches with primary key any of the primary keys |
|
462 TInt prikeyIndex( iPrimaryKeys.Find( aKeyEvent.iScanCode )); |
|
463 |
|
464 if ( prikeyIndex != KErrNotFound ) |
|
465 { |
|
466 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::HandleKeyEventL() : Primary key pressed" ) ); |
|
467 |
|
468 // store the index of matched primary key |
|
469 iLastPrimaryKeyIndex = prikeyIndex; |
|
470 |
|
471 // devicelock query only needs the primary key to match |
|
472 if ( iType == EPolicyDevicelockQuery ) |
|
473 { |
|
474 matchFound = ETrue; |
|
475 } |
|
476 else |
|
477 { |
|
478 // collect the possible secondary key candidates to the waiting keys array |
|
479 iWaitingKeys.Reset( ); |
|
480 for (TInt x( 0); x < iPrimaryKeys.Count( ); x++ ) |
|
481 { |
|
482 if ( iPrimaryKeys[x] == aKeyEvent.iScanCode && iSecondaryKeys.Count( )> x ) |
|
483 { |
|
484 TraceDump( INFO_LEVEL, ( _L( "CKeyLockPolicyApiImpl::HandleKeyEventL() : Waiting for key: 0x%x" ), iSecondaryKeys[x] ) ); |
|
485 iWaitingKeys.Append( iSecondaryKeys[x] ); |
|
486 } |
|
487 } |
|
488 |
|
489 // start timer for primary key timeout |
|
490 iKeyLockTimer->Start( iTimeout, iTimeout, TCallBack( |
|
491 HandleKeyLockTimerTimeout, this ) ); |
|
492 |
|
493 // primary key has been pressed |
|
494 iPrimaryKeyDown = ETrue; |
|
495 } |
|
496 } |
|
497 else |
|
498 { |
|
499 // if no match was found cancel timer and start over |
|
500 TraceDump( INFO_LEVEL, ( _L( "CKeyLockPolicyApiImpl::HandleKeyEventL() : Unknown key, not handled: 0x%x" ), aKeyEvent.iScanCode ) ); |
|
501 |
|
502 iPrimaryKeyDown = EFalse; |
|
503 iKeyLockTimer->Cancel( ); |
|
504 iLastPrimaryKeyIndex = 0xffffffff; |
|
505 } |
|
506 } |
|
507 } |
|
508 else |
|
509 { |
|
510 TraceDump( INFO_LEVEL, ( _L( "CKeyLockPolicyApiImpl::HandleKeyEventL() : not initialized or not allowed" ) ) ); |
|
511 } |
|
512 } |
|
513 return matchFound; |
|
514 } |
|
515 |
|
516 // --------------------------------------------------------------------------- |
|
517 // Returns true if the last received key matched any of the primary keys |
|
518 // stored in the policy |
|
519 // --------------------------------------------------------------------------- |
|
520 // |
|
521 TBool CKeyLockPolicyApiImpl::PrimaryKeyPressed( ) |
|
522 { |
|
523 return iPrimaryKeyDown; |
|
524 } |
|
525 |
|
526 // --------------------------------------------------------------------------- |
|
527 // Returns the last received key if it was a primary key |
|
528 // --------------------------------------------------------------------------- |
|
529 // |
|
530 TUint CKeyLockPolicyApiImpl::GetLastPrimaryKey( ) |
|
531 { |
|
532 if ( iLastPrimaryKeyIndex < iPrimaryKeys.Count( ) ) |
|
533 { |
|
534 return iPrimaryKeys[iLastPrimaryKeyIndex]; |
|
535 } |
|
536 else |
|
537 { |
|
538 return 0; |
|
539 } |
|
540 } |
|
541 |
|
542 // --------------------------------------------------------------------------- |
|
543 // MCenRepNotifyHandlerCallback. Changes in the observed central |
|
544 // repository keys are communicated trough this method. |
|
545 // --------------------------------------------------------------------------- |
|
546 // |
|
547 void CKeyLockPolicyApiImpl::HandleNotifyInt( TUint32 aId, TInt aNewValue ) |
|
548 { |
|
549 switch ( aId ) |
|
550 { |
|
551 case KLockKeyguardAllow: |
|
552 { |
|
553 // keyguard feature has been enabled/disabled |
|
554 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::HandleNotifyInt() : KLockKeyguardAllow" ) ); |
|
555 aNewValue == 0 ? iAllowed = EFalse : iAllowed = ETrue; |
|
556 } |
|
557 break; |
|
558 |
|
559 case KLockPolicyMode: |
|
560 { |
|
561 // keylock policy mode has been changed |
|
562 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::HandleNotifyInt() : KLockPolicyMode" ) ); |
|
563 // mask has changed |
|
564 iMask = iType << KTypeShift|aNewValue << KModeShift; |
|
565 // key configuration has changed |
|
566 iPrimaryKeys.Reset( ); |
|
567 iSecondaryKeys.Reset( ); |
|
568 TUint32 x(0), k1(0), k2(0); |
|
569 while ( GetKeyCombination( x, k1, k2 )== KErrNone ) |
|
570 { |
|
571 iPrimaryKeys.Append( k1 ); |
|
572 iSecondaryKeys.Append( k2 ); |
|
573 x++; |
|
574 } |
|
575 // reset the memory |
|
576 iPrimaryKeyDown = EFalse; |
|
577 iLastPrimaryKeyIndex = 0xffffffff; |
|
578 } |
|
579 break; |
|
580 |
|
581 default: |
|
582 break; |
|
583 } |
|
584 } |
|
585 |
|
586 // --------------------------------------------------------------------------- |
|
587 // Default C++ constructor |
|
588 // --------------------------------------------------------------------------- |
|
589 // |
|
590 CKeyLockPolicyApiImpl::CKeyLockPolicyApiImpl( TLockPolicyType aType ) : |
|
591 iMode( 1), iType( aType), iInitialised( EFalse) |
|
592 { |
|
593 iMask = aType << KTypeShift; |
|
594 } |
|
595 |
|
596 // --------------------------------------------------------------------------- |
|
597 // Keylock policy construction |
|
598 // --------------------------------------------------------------------------- |
|
599 // |
|
600 void CKeyLockPolicyApiImpl::ConstructL( ) |
|
601 { |
|
602 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::ConstructL() started" ) ); |
|
603 TInt err( KErrNone); |
|
604 |
|
605 // Create a connection to the repository |
|
606 TRAP( err, iRep = CRepository::NewL( KCRUidLockConf ) ); |
|
607 if ( err == KErrNone ) |
|
608 { |
|
609 // get the lock policy mode |
|
610 TInt mode( NULL); |
|
611 err = iRep->Get( KLockPolicyMode, mode ); |
|
612 if ( err == KErrNone && mode ) |
|
613 { |
|
614 iMode = mode; |
|
615 |
|
616 // every key in the configuration should have the mask below |
|
617 iMask |= iMode << KModeShift; |
|
618 |
|
619 // get the timeout between key presses |
|
620 TInt timeout( NULL); |
|
621 err = iRep->Get( KLockTimerInterval, timeout ); |
|
622 if ( err == KErrNone && timeout > NULL ) |
|
623 { |
|
624 iTimeout = timeout; |
|
625 |
|
626 // collect supported key configuration |
|
627 iPrimaryKeys.Reset( ); |
|
628 iSecondaryKeys.Reset( ); |
|
629 TUint32 x(0), k1(0), k2(0); |
|
630 while ( GetKeyCombination( x, k1, k2 )== KErrNone ) |
|
631 { |
|
632 iPrimaryKeys.Append( k1 ); |
|
633 iSecondaryKeys.Append( k2 ); |
|
634 x++; |
|
635 } |
|
636 if ( iPrimaryKeys.Count( )> 0 && iSecondaryKeys.Count( )> 0 ) |
|
637 { |
|
638 TraceDump( INFO_LEVEL, _L( "CRepository::NewL(): Initialised" ) ); |
|
639 iInitialised = ETrue; |
|
640 } |
|
641 |
|
642 iPrimaryKeyDown = EFalse; |
|
643 iLastPrimaryKeyIndex = 0xffffffff; |
|
644 |
|
645 // whether keyguard feature is enabled or disabled |
|
646 // by default we want keyguard to be enabled |
|
647 TInt allow( 1 ); |
|
648 iRep->Get( KLockKeyguardAllow, allow ); |
|
649 iAllowed = allow; |
|
650 |
|
651 // create childs |
|
652 iKeyLockTimer = CPeriodic::NewL( CActive::EPriorityUserInput ); |
|
653 iAllowNotif = CCenRepNotifyHandler::NewL( *this, *iRep, |
|
654 CCenRepNotifyHandler::EIntKey, KLockKeyguardAllow ); |
|
655 iAllowNotif->StartListeningL( ); |
|
656 iModeNotif = CCenRepNotifyHandler::NewL( *this, *iRep, |
|
657 CCenRepNotifyHandler::EIntKey, KLockPolicyMode ); |
|
658 iModeNotif->StartListeningL( ); |
|
659 } |
|
660 else |
|
661 { |
|
662 TraceDump( INFO_LEVEL, _L( "No time out defined: FAILED!" ) ); |
|
663 } |
|
664 } |
|
665 else |
|
666 { |
|
667 TraceDump( INFO_LEVEL, _L( "No mode has been set: FAILED!" ) ); |
|
668 } |
|
669 } |
|
670 else |
|
671 { |
|
672 TraceDump( INFO_LEVEL, _L( "CRepository::NewL( KCRUidLockConf ) ) FAILED!!" ) ); |
|
673 } |
|
674 |
|
675 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::ConstructL() finished" ) ); |
|
676 } |
|
677 |
|
678 // --------------------------------------------------------------------------- |
|
679 // A call back to the keylock timer, the allowed time window for pressing |
|
680 // the secondary key to get a match has passed. |
|
681 // --------------------------------------------------------------------------- |
|
682 // |
|
683 TInt CKeyLockPolicyApiImpl::HandleKeyLockTimerTimeout( TAny* aSelf ) |
|
684 { |
|
685 TraceDump( INFO_LEVEL, _L( "CKeyLockPolicyApiImpl::HandleKeyLockTimerTimeout()" ) ); |
|
686 CKeyLockPolicyApiImpl *self = reinterpret_cast< CKeyLockPolicyApiImpl* >( aSelf ); |
|
687 |
|
688 // reset the memory |
|
689 self->iPrimaryKeyDown = EFalse; |
|
690 self->iLastPrimaryKeyIndex = 0xffffffff; |
|
691 self->iKeyLockTimer->Cancel( ); |
|
692 |
|
693 return KErrNone; |
|
694 } |
|
695 |
|
696 // EOF |