86 |
86 |
87 _LIT( KRESOURCEFILE, "\\resource\\aknnotpi.rsc" ); |
87 _LIT( KRESOURCEFILE, "\\resource\\aknnotpi.rsc" ); |
88 _LIT_SECURITY_POLICY_C1( KWritePolicy, ECapabilityWriteDeviceData ); |
88 _LIT_SECURITY_POLICY_C1( KWritePolicy, ECapabilityWriteDeviceData ); |
89 |
89 |
90 |
90 |
91 /** |
91 |
92 * CAknKeylockScreenSaverObserver captures primary keys |
92 |
93 * from screensaver when screen saver is active. |
93 |
94 * |
|
95 * @lib aknoldstylenotif.lib |
|
96 * @since 3.2 |
|
97 */ |
|
98 NONSHARABLE_CLASS( CAknKeylockScreenSaverObserver ): public CActive |
|
99 { |
|
100 public: |
|
101 |
|
102 /** |
|
103 * Creates instance of the CAknKeylockScreenSaverObserver class. |
|
104 * |
|
105 * @param aWindowGroup application window group used to capture primary keys |
|
106 * @return Returns the instance just created. |
|
107 */ |
|
108 static CAknKeylockScreenSaverObserver* NewL( RWindowGroup& aWindowGroup ); |
|
109 |
|
110 /** |
|
111 * Destructor. |
|
112 */ |
|
113 ~CAknKeylockScreenSaverObserver(); |
|
114 |
|
115 public: |
|
116 |
|
117 /** |
|
118 * Starts asynchronic listening KUidCurrentCall event |
|
119 * |
|
120 * @return KErrNone: if no errors |
|
121 * @return KErrInUse: if already listening |
|
122 */ |
|
123 TInt Start(); |
|
124 |
|
125 /** |
|
126 * Stops asynchronic listening KUidAutolockStatus event |
|
127 */ |
|
128 void Stop(); |
|
129 |
|
130 public: |
|
131 |
|
132 /** |
|
133 * Method handles the lock state changes. |
|
134 * |
|
135 * @param aStatus The new lock state |
|
136 */ |
|
137 void SetLockStatus( TBool aKeylockEnabled, TBool aAutolockEnabled ); |
|
138 |
|
139 private: // constructors |
|
140 |
|
141 /** |
|
142 * C++ default constructor. |
|
143 * |
|
144 * @param aAppUi (pointer to autolock appui) |
|
145 */ |
|
146 CAknKeylockScreenSaverObserver( RWindowGroup& aWindowGroup ); |
|
147 |
|
148 /** |
|
149 * Symbian OS constructor. |
|
150 */ |
|
151 void ConstructL(); |
|
152 |
|
153 private: // from CActive |
|
154 |
|
155 /** @see CActive::RunL() */ |
|
156 void RunL(); |
|
157 |
|
158 /** @see CActive::DoCancel() */ |
|
159 void DoCancel(); |
|
160 |
|
161 private: |
|
162 |
|
163 /** |
|
164 * Used to capture primary keys defined in keylocking policies |
|
165 */ |
|
166 void CapturePrimaryKeys( TBool aCapture ); |
|
167 |
|
168 private: // data |
|
169 |
|
170 // screen saver on property |
|
171 RProperty iScreenSaverActiveProperty; |
|
172 |
|
173 // if screensaver is active or not |
|
174 TBool iScreenSaverActive; |
|
175 |
|
176 // if primary keys have been captured |
|
177 TBool iCaptured; |
|
178 |
|
179 // locking states |
|
180 TBool iKeylockEnabled; |
|
181 TBool iAutolockEnabled; |
|
182 |
|
183 // left softkey capture |
|
184 TInt iLeftSoftKey; |
|
185 |
|
186 // a reference to application window group |
|
187 RWindowGroup& iWindowGroup; |
|
188 |
|
189 // keylockpolicy support (not owned) |
|
190 CKeyLockPolicyApi* iUnlockPolicyApi; |
|
191 |
|
192 // keylockpolicy support (not owned) |
|
193 CKeyLockPolicyApi* iDevicelockPolicyApi; |
|
194 |
|
195 // primary key captures |
|
196 RArray<TUint> iPrimaryKeyCaptures; |
|
197 }; |
|
198 |
|
199 // =========================================================================== |
|
200 // class CAknKeylockScreenSaverObserver |
|
201 // =========================================================================== |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // Constructs a new entry with given values. |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 CAknKeylockScreenSaverObserver* CAknKeylockScreenSaverObserver::NewL( |
|
208 RWindowGroup& aWindowGroup ) |
|
209 { |
|
210 CAknKeylockScreenSaverObserver* self = |
|
211 new (ELeave) CAknKeylockScreenSaverObserver( aWindowGroup ); |
|
212 CleanupStack::PushL( self ); |
|
213 self->ConstructL(); |
|
214 CleanupStack::Pop( self ); |
|
215 return self; |
|
216 } |
|
217 |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Destructor |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 CAknKeylockScreenSaverObserver::~CAknKeylockScreenSaverObserver() |
|
224 { |
|
225 Cancel(); |
|
226 |
|
227 // Close the property handle. |
|
228 iScreenSaverActiveProperty.Close(); |
|
229 |
|
230 // Release key captures. |
|
231 CapturePrimaryKeys( EFalse ); |
|
232 |
|
233 // Delete policies. |
|
234 delete iUnlockPolicyApi; |
|
235 delete iDevicelockPolicyApi; |
|
236 } |
|
237 |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // Starts listening to the KScreenSaverOn event. |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 TInt CAknKeylockScreenSaverObserver::Start() |
|
244 { |
|
245 if ( IsActive() ) |
|
246 { |
|
247 return KErrInUse; |
|
248 } |
|
249 iStatus = KRequestPending; |
|
250 iScreenSaverActiveProperty.Subscribe( iStatus ); |
|
251 SetActive(); |
|
252 |
|
253 return KErrNone; |
|
254 } |
|
255 |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Stops listening to the KScreenSaverOn event. |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 void CAknKeylockScreenSaverObserver::Stop() |
|
262 { |
|
263 if ( !IsActive() ) |
|
264 { |
|
265 return; |
|
266 } |
|
267 Cancel(); |
|
268 iScreenSaverActiveProperty.Cancel(); |
|
269 } |
|
270 |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // C++ constructor |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 CAknKeylockScreenSaverObserver::CAknKeylockScreenSaverObserver( |
|
277 RWindowGroup& aWindowGroup ) |
|
278 : CActive( 0 ), |
|
279 iScreenSaverActive( EFalse ), |
|
280 iCaptured( EFalse ), |
|
281 iKeylockEnabled( EFalse ), |
|
282 iAutolockEnabled( EFalse ), |
|
283 iLeftSoftKey( NULL ), |
|
284 iWindowGroup( aWindowGroup ) |
|
285 { |
|
286 } |
|
287 |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // Second phase constructor. |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 void CAknKeylockScreenSaverObserver::ConstructL() |
|
294 { |
|
295 // Add this active object to the scheduler. |
|
296 CActiveScheduler::Add( this ); |
|
297 |
|
298 // We need policies to poll primary keys. |
|
299 iUnlockPolicyApi = CKeyLockPolicyApi::NewL( EPolicyDeactivateKeyguard ); |
|
300 if ( !iUnlockPolicyApi->HasConfiguration() ) |
|
301 { |
|
302 delete iUnlockPolicyApi; |
|
303 iUnlockPolicyApi = NULL; |
|
304 } |
|
305 |
|
306 // we need policies to poll primary keys |
|
307 iDevicelockPolicyApi = CKeyLockPolicyApi::NewL( EPolicyDevicelockQuery ); |
|
308 if ( !iDevicelockPolicyApi->HasConfiguration() ) |
|
309 { |
|
310 delete iDevicelockPolicyApi; |
|
311 iDevicelockPolicyApi = NULL; |
|
312 } |
|
313 } |
|
314 |
|
315 |
|
316 // --------------------------------------------------------------------------- |
|
317 // From base class CActive. |
|
318 // Handles change in the screen saver state. |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 void CAknKeylockScreenSaverObserver::RunL() |
|
322 { |
|
323 if ( iKeylockEnabled || iAutolockEnabled ) |
|
324 { |
|
325 // Resubscribe before processing new value to prevent missing updates. |
|
326 Start(); |
|
327 } |
|
328 |
|
329 TInt screenSaverState; |
|
330 iScreenSaverActiveProperty.Get( screenSaverState ); |
|
331 // Primary keys are captured from screensaver when screensaver |
|
332 // is the top most application. |
|
333 if ( screenSaverState > NULL ) |
|
334 { |
|
335 __ASSERT_DEBUG( !iCaptured, |
|
336 Panic( EAknPanicKeyLockObserverAlreadyExists ) ); |
|
337 iScreenSaverActive = ETrue; |
|
338 CapturePrimaryKeys( ETrue ); |
|
339 } |
|
340 else |
|
341 { |
|
342 // If screensaver is disabled, stop capturing primary key events. |
|
343 if ( iScreenSaverActive ) |
|
344 { |
|
345 CapturePrimaryKeys( EFalse ); |
|
346 } |
|
347 iScreenSaverActive = EFalse; |
|
348 } |
|
349 } |
|
350 |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // Set the lock status. |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 void CAknKeylockScreenSaverObserver::SetLockStatus( TBool aKeylockEnabled, |
|
357 TBool aAutolockEnabled ) |
|
358 { |
|
359 iKeylockEnabled = aKeylockEnabled; |
|
360 iAutolockEnabled = aAutolockEnabled; |
|
361 |
|
362 if ( iKeylockEnabled || iAutolockEnabled ) |
|
363 { |
|
364 // Start observing screensaver activation. |
|
365 Start(); |
|
366 } |
|
367 else |
|
368 { |
|
369 if ( iScreenSaverActive ) |
|
370 { |
|
371 CapturePrimaryKeys( EFalse ); |
|
372 } |
|
373 // Screensaver is only observed when keylock is enabled. |
|
374 Stop(); |
|
375 } |
|
376 } |
|
377 |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // Capture or uncapture primary keys. |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 void CAknKeylockScreenSaverObserver::CapturePrimaryKeys( TBool aCapture ) |
|
384 { |
|
385 if ( aCapture ) |
|
386 { |
|
387 if ( iScreenSaverActive && !iCaptured ) |
|
388 { |
|
389 if ( iKeylockEnabled && !iAutolockEnabled ) |
|
390 { |
|
391 iCaptured = ETrue; |
|
392 // If no unlocking policy has been defined, |
|
393 // the default primary key is the left soft key. |
|
394 if ( !iUnlockPolicyApi ) |
|
395 { |
|
396 // Capture LSK (starts unlock prosess, capturing |
|
397 // bypasses screensaver) |
|
398 iLeftSoftKey = iWindowGroup.CaptureKey( EKeyDevice0, 0, 0 ); |
|
399 } |
|
400 else |
|
401 { |
|
402 iPrimaryKeyCaptures.Reset(); |
|
403 TUint32 index( 0 ); |
|
404 TUint32 primaryKey( 0 ); |
|
405 TUint32 secondaryKey( 0 ); |
|
406 while ( iUnlockPolicyApi->GetKeyCombination( index, |
|
407 primaryKey, |
|
408 secondaryKey ) == KErrNone ) |
|
409 { |
|
410 iPrimaryKeyCaptures.Append( |
|
411 iWindowGroup.CaptureKeyUpAndDowns( primaryKey, 0, 0 ) ); |
|
412 index++; |
|
413 } |
|
414 } |
|
415 } |
|
416 else |
|
417 { |
|
418 if ( iKeylockEnabled && iAutolockEnabled ) |
|
419 { |
|
420 iCaptured = ETrue; |
|
421 // If no devicelock query policy has been defined, |
|
422 // the default primary key is the left soft key. |
|
423 if ( !iDevicelockPolicyApi ) |
|
424 { |
|
425 // Capture LSK (starts unlock prosess, |
|
426 // capturing bypasses screensaver). |
|
427 iLeftSoftKey = iWindowGroup.CaptureKey( EKeyDevice0, 0, 0 ); |
|
428 } |
|
429 else |
|
430 { |
|
431 iPrimaryKeyCaptures.Reset(); |
|
432 TUint32 index( 0 ); |
|
433 TUint32 primaryKey( 0 ); |
|
434 TUint32 secondaryKey( 0 ); |
|
435 while ( iDevicelockPolicyApi->GetKeyCombination( index, primaryKey, secondaryKey ) == KErrNone ) |
|
436 { |
|
437 iPrimaryKeyCaptures.Append( |
|
438 iWindowGroup.CaptureKeyUpAndDowns( primaryKey, 0, 0 ) ); |
|
439 index++; |
|
440 } |
|
441 } |
|
442 } |
|
443 } |
|
444 } |
|
445 } |
|
446 else |
|
447 { |
|
448 if (iCaptured) |
|
449 { |
|
450 if (iLeftSoftKey > 0) |
|
451 { |
|
452 iWindowGroup.CancelCaptureKey(iLeftSoftKey); |
|
453 } |
|
454 iLeftSoftKey = 0; |
|
455 |
|
456 if (iPrimaryKeyCaptures.Count() > 0) |
|
457 { |
|
458 for (TInt x = 0; x < iPrimaryKeyCaptures.Count(); x++) |
|
459 { |
|
460 iWindowGroup.CancelCaptureKeyUpAndDowns(iPrimaryKeyCaptures[x]); |
|
461 } |
|
462 iPrimaryKeyCaptures.Reset(); |
|
463 } |
|
464 |
|
465 iCaptured = EFalse; |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 |
|
471 // --------------------------------------------------------------------------- |
|
472 // From base class CActive. |
|
473 // Cancels event listening. |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 void CAknKeylockScreenSaverObserver::DoCancel() |
|
477 { |
|
478 iScreenSaverActiveProperty.Cancel(); |
|
479 } |
|
480 |
94 |
481 |
95 |
482 // =========================================================================== |
96 // =========================================================================== |
483 // class CAknLockedNote. |
97 // class CAknLockedNote. |
484 // =========================================================================== |
98 // =========================================================================== |