1 /* |
|
2 * Copyright (c) 2005-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: System state observer and notifier |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <connect/sbdefs.h> |
|
20 #include <aipspropertyobserver.h> |
|
21 #include <settingsinternalcrkeys.h> // for KSettingsScreenSaverPeriod |
|
22 #include <e32property.h> |
|
23 #include <aiutility.h> |
|
24 #include <e32base.h> |
|
25 #include <centralrepository.h> |
|
26 #include <activeidle2domaincrkeys.h> |
|
27 #include "aifwpanic.h" |
|
28 #include "aipluginstatemanager.h" |
|
29 #include "aipluginstatemachineimpl.h" |
|
30 #include "ailightstatusobserver.h" |
|
31 #include "aicallstatusobserver.h" |
|
32 #include "aifocusobserver.h" |
|
33 #include "aikeylockobserver.h" |
|
34 #include "aibackuprestorestatusobserver.h" |
|
35 #include "aienvironmentchangeobserver.h" |
|
36 #include "aiuiframeworkobserverimpl.h" |
|
37 |
|
38 #include <ScreensaverInternalPSKeys.h> // this include needs to be last |
|
39 |
|
40 #include "debug.h" |
|
41 |
|
42 const TInt KMinuteInSeconds( 60 ); |
|
43 const TInt KSecondInMikroSeconds( 1000*1000 ); |
|
44 const TInt KAIFadeOutEstimateMikroSeconds( 10 * KSecondInMikroSeconds ); |
|
45 const TInt KTwoMinutesInMikroSeconds( 2 * KMinuteInSeconds * KSecondInMikroSeconds ); |
|
46 |
|
47 #define AI2_OPTION_RESUME_AT_CREATION |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======== |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CAiPluginStateManager::NewL() |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 CAiPluginStateManager* CAiPluginStateManager::NewL() |
|
56 { |
|
57 CAiPluginStateManager* self = new (ELeave) CAiPluginStateManager; |
|
58 |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop( self ); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CAiPluginStateManager::~CAiPluginStateManager() |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 CAiPluginStateManager::~CAiPluginStateManager() |
|
71 { |
|
72 iStateMachines.ResetAndDestroy(); |
|
73 |
|
74 DestroySystemStateObservers(); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CAiPluginStateManager::CAiPluginStateManager() |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 CAiPluginStateManager::CAiPluginStateManager() |
|
82 { |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CAiPluginStateManager::ConstructL() |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 void CAiPluginStateManager::ConstructL() |
|
90 { |
|
91 TInt value( 0 ); |
|
92 |
|
93 TInt err( RProperty::Get( KCRUidPersonalizationSettings, |
|
94 KSettingsScreenSaverPeriod, value ) ); |
|
95 |
|
96 if( err == KErrNone ) |
|
97 { |
|
98 iT1Delay = ( value * KMinuteInSeconds * KSecondInMikroSeconds ) |
|
99 + KAIFadeOutEstimateMikroSeconds; |
|
100 } |
|
101 else |
|
102 { |
|
103 // default when error to 2 minutes |
|
104 iT1Delay = KTwoMinutesInMikroSeconds; |
|
105 } |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // CAiPluginStateManager::CreateSystemStateObserversL() |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 void CAiPluginStateManager::CreateSystemStateObserversL() |
|
113 { |
|
114 iT1Timer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
115 |
|
116 iBackupOperationObserver = CAiBackupRestoreStatusObserver::NewL( this ); |
|
117 |
|
118 iCallStateObserver = CAiCallStatusObserver::NewL( this ); |
|
119 |
|
120 iLightStateObserver = CAiLightStatusObserver::NewL( this ); |
|
121 |
|
122 iFocusObserver = CAiFocusObserver::NewL( this ); |
|
123 |
|
124 iKeylockObserver = CAiKeylockObserver::NewL( this ); |
|
125 |
|
126 // Environment change observer notifies time/date/midnight/language |
|
127 // changes |
|
128 iEnvironmentObserver = CAiEnvironmentChangeObserver::NewL( this ); |
|
129 |
|
130 // Ui framework observer notifies currently general theme changes |
|
131 iFrameworkObserver = CAiUiFrameworkObserverImpl::NewL( *this ); |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CAiPluginStateManager::DestroySystemStateObservers() |
|
136 // ---------------------------------------------------------------------------- |
|
137 // |
|
138 void CAiPluginStateManager::DestroySystemStateObservers() |
|
139 { |
|
140 if( iT1Timer ) |
|
141 { |
|
142 iT1Timer->Cancel(); |
|
143 |
|
144 delete iT1Timer; |
|
145 iT1Timer = NULL; |
|
146 } |
|
147 |
|
148 delete iBackupOperationObserver; |
|
149 iBackupOperationObserver = NULL; |
|
150 |
|
151 delete iCallStateObserver; |
|
152 iCallStateObserver = NULL; |
|
153 |
|
154 delete iLightStateObserver; |
|
155 iLightStateObserver = NULL; |
|
156 |
|
157 delete iFocusObserver; |
|
158 iFocusObserver = NULL; |
|
159 |
|
160 delete iKeylockObserver; |
|
161 iKeylockObserver = NULL; |
|
162 |
|
163 delete iEnvironmentObserver; |
|
164 iEnvironmentObserver = NULL; |
|
165 |
|
166 delete iFrameworkObserver; |
|
167 iFrameworkObserver = NULL; |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // CAiPluginStateManager::UiFwObserver() |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 MAiUiFrameworkObserver* CAiPluginStateManager::UiFwObserver() const |
|
175 { |
|
176 return iFrameworkObserver; |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------- |
|
180 // CAiPluginStateManager::ReportStateChange() |
|
181 // ---------------------------------------------------------------------------- |
|
182 // |
|
183 void CAiPluginStateManager::ReportStateChange( TAiStateChanges aState ) |
|
184 { |
|
185 if( !iIsDeviceStarted ) |
|
186 { |
|
187 if( aState == ESMAISystemBoot ) |
|
188 { |
|
189 iIsDeviceStarted = ETrue; |
|
190 } |
|
191 } |
|
192 |
|
193 if( aState == ESMAISystemBoot ) |
|
194 { |
|
195 return; |
|
196 } |
|
197 |
|
198 ProcessStateChangeForAll( aState ); |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------------------------- |
|
202 // CAiPluginStateManager::StateVariable() |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 TBool CAiPluginStateManager::StateVariable( TAiStateVariable aStateChange ) |
|
206 { |
|
207 switch ( aStateChange ) |
|
208 { |
|
209 case ESMAICallStatus: |
|
210 { |
|
211 return CallOngoing(); |
|
212 } |
|
213 case ESMAILightStatus: |
|
214 { |
|
215 return LightsOn(); |
|
216 } |
|
217 case ESMAIBackupRestoreStatus: |
|
218 { |
|
219 return BackupOngoing(); |
|
220 } |
|
221 case ESMAIIdleFocusStatus: |
|
222 { |
|
223 return IdleFocused(); |
|
224 } |
|
225 default: |
|
226 { |
|
227 return EFalse; |
|
228 } |
|
229 } |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------------------------- |
|
233 // CAiPluginStateManager::RestartSuspendTimer() |
|
234 // ---------------------------------------------------------------------------- |
|
235 // |
|
236 void CAiPluginStateManager::RestartSuspendTimer() |
|
237 { |
|
238 if( iT1Timer ) |
|
239 { |
|
240 iT1Timer->Cancel(); |
|
241 |
|
242 iT1Timer->Start( iT1Delay, iT1Delay, |
|
243 TCallBack( T1TimerCallback, this ) ); |
|
244 } |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // CAiPluginStateManager::PluginCreatedL() |
|
249 // ---------------------------------------------------------------------------- |
|
250 // |
|
251 void CAiPluginStateManager::PluginCreatedL( CAiContentPublisher& aPlugin ) |
|
252 { |
|
253 // Create a new state machine for the plugin from the heap |
|
254 // and append the machine to our local array. |
|
255 CAiPluginStateMachine* machine = |
|
256 new ( ELeave ) CAiPluginStateMachine( *this, aPlugin ); |
|
257 |
|
258 // Important to append first so failure will be handled properly |
|
259 CleanupStack::PushL( machine ); |
|
260 iStateMachines.AppendL( machine ); |
|
261 CleanupStack::Pop( machine ); |
|
262 |
|
263 // This will effectively resume the plugin NOW. |
|
264 ProcessStateChange( ESMAISystemBoot, *machine ); |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // CAiPluginStateManager::PluginDestroyed() |
|
269 // ---------------------------------------------------------------------------- |
|
270 // |
|
271 void CAiPluginStateManager::PluginDestroyed( CAiContentPublisher& aPlugin ) |
|
272 { |
|
273 // plugin has beed destroyed, remove the state machine also |
|
274 for( TInt i = 0; i < iStateMachines.Count(); i++ ) |
|
275 { |
|
276 if( &iStateMachines[i]->Plugin() == &aPlugin ) |
|
277 { |
|
278 iStateMachines[i]->HandleEvent( ESMAISystemShutdown ); |
|
279 delete iStateMachines[i]; |
|
280 |
|
281 iStateMachines.Remove( i ); |
|
282 break; |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 // ---------------------------------------------------------------------------- |
|
288 // CAiPluginStateManager::AllPluginsCreated() |
|
289 // ---------------------------------------------------------------------------- |
|
290 // |
|
291 void CAiPluginStateManager::AllPluginsCreated() |
|
292 { |
|
293 // Currently we get this event via pluginmanager -> aifw -> EAISMSystemBoot event |
|
294 // so no implementation required. We might want to handle this locally in the |
|
295 // future though. Current impl is such because RefreshUI for ui controller |
|
296 // needs to after the plugins are resumed -> If we handle this here it is not |
|
297 // garanteed. |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------------------------------- |
|
301 // CAiPluginStateManager::AllPluginsDestroyed() |
|
302 // ---------------------------------------------------------------------------- |
|
303 // |
|
304 void CAiPluginStateManager::AllPluginsDestroyed() |
|
305 { |
|
306 // Plugins have been destroyed, so destroy the state machines also. |
|
307 iStateMachines.ResetAndDestroy(); |
|
308 } |
|
309 |
|
310 // ---------------------------------------------------------------------------- |
|
311 // CAiPluginStateManager::TranslateReason() |
|
312 // ---------------------------------------------------------------------------- |
|
313 // |
|
314 TAiTransitionReason CAiPluginStateManager::TranslateReason( |
|
315 TAiStateChanges aStateChange ) |
|
316 { |
|
317 switch ( aStateChange ) |
|
318 { |
|
319 case ESMAIBacklightOn: |
|
320 { |
|
321 return EAiBacklightOn; |
|
322 } |
|
323 case ESMAIBacklightOff: |
|
324 { |
|
325 return EAiBacklightOff; |
|
326 } |
|
327 case ESMAIBackupOn: |
|
328 { |
|
329 return EAiBackupRestoreStarted; |
|
330 } |
|
331 case ESMAIBackupOff: |
|
332 { |
|
333 return EAiBackupRestoreEnded; |
|
334 } |
|
335 case ESMAIInCall: |
|
336 { |
|
337 return EAiPhoneCallStarted; |
|
338 } |
|
339 case ESMAINoCall: |
|
340 { |
|
341 return EAiPhoneCallEnded; |
|
342 } |
|
343 case ESMAISystemBoot: |
|
344 { |
|
345 return EAiSystemStartup; |
|
346 } |
|
347 case ESMAILocaleChanged: |
|
348 { |
|
349 return EAiLanguageChanged; |
|
350 } |
|
351 case ESMAIIdleForeground: |
|
352 { |
|
353 return EAiIdleForeground; |
|
354 } |
|
355 case ESMAIIdleBackground: |
|
356 { |
|
357 return EAiIdleBackground; |
|
358 } |
|
359 case ESMAITimeChanged: |
|
360 { |
|
361 return EAiTimeChanged; |
|
362 } |
|
363 case ESMAIMidnightCrossover: |
|
364 { |
|
365 return EAiMidnightPassed; |
|
366 } |
|
367 case ESMAIRelayoutScreen: |
|
368 { |
|
369 return EAiScreenLayoutChanged; |
|
370 } |
|
371 case ESMAIReportThemeChangeStarted: |
|
372 { |
|
373 return EAiUiDefinitionChangeStarted; |
|
374 } |
|
375 case ESMAIReportThemeChangeReady: |
|
376 { |
|
377 return EAiUiDefinitionChangeEnded; |
|
378 } |
|
379 case ESMAIGeneralThemeChanged: |
|
380 { |
|
381 return EAiGeneralThemeChanged; |
|
382 } |
|
383 case ESMAISystemShutdown: |
|
384 { |
|
385 return EAiSystemShutdown; |
|
386 } |
|
387 case ESMAIT1Timeout: |
|
388 { |
|
389 return EAiSuspendPlugins; |
|
390 } |
|
391 case ESMAIKeylockEnabled: |
|
392 { |
|
393 return EAiKeylockEnabled; |
|
394 } |
|
395 case ESMAIKeylockDisabled: |
|
396 { |
|
397 return EAiKeylockDisabled; |
|
398 } |
|
399 case ESMAIOffLine: |
|
400 { |
|
401 return EAiIdleOffLine; |
|
402 } |
|
403 case ESMAIOnLine: |
|
404 { |
|
405 return EAiIdleOnLine; |
|
406 } |
|
407 case ESMAIPageSwitch: |
|
408 { |
|
409 return EAiIdlePageSwitch; |
|
410 } |
|
411 case ESMAIUnknownState: // fallthrough |
|
412 default: |
|
413 { |
|
414 return EAiUnknownTransitionReason; |
|
415 } |
|
416 } |
|
417 } |
|
418 |
|
419 // ---------------------------------------------------------------------------- |
|
420 // CAiPluginStateManager::ProcessStateChange() |
|
421 // ---------------------------------------------------------------------------- |
|
422 // |
|
423 void CAiPluginStateManager::ProcessStateChange( TAiStateChanges aState, |
|
424 CAiPluginStateMachine& aMachine ) |
|
425 { |
|
426 aMachine.HandleEvent( aState ); |
|
427 } |
|
428 |
|
429 // ---------------------------------------------------------------------------- |
|
430 // CAiPluginStateManager::ProcessOnlineState() |
|
431 // ---------------------------------------------------------------------------- |
|
432 // |
|
433 void CAiPluginStateManager::ProcessOnlineState( CAiContentPublisher& aPlugin ) |
|
434 { |
|
435 for ( TInt i = 0; i < iStateMachines.Count(); i++ ) |
|
436 { |
|
437 if( &iStateMachines[i]->Plugin() == &aPlugin ) |
|
438 { |
|
439 iStateMachines[i]->HandleEvent( ESMAIOnLine ); |
|
440 break; |
|
441 } |
|
442 } |
|
443 } |
|
444 |
|
445 // ---------------------------------------------------------------------------- |
|
446 // CAiPluginStateManager::ProcessOfflineState() |
|
447 // ---------------------------------------------------------------------------- |
|
448 // |
|
449 void CAiPluginStateManager::ProcessOfflineState( CAiContentPublisher& aPlugin ) |
|
450 { |
|
451 for ( TInt i = 0; i < iStateMachines.Count(); i++ ) |
|
452 { |
|
453 if( &iStateMachines[i]->Plugin() == &aPlugin ) |
|
454 { |
|
455 iStateMachines[i]->HandleEvent( ESMAIOffLine ); |
|
456 break; |
|
457 } |
|
458 } |
|
459 } |
|
460 |
|
461 // ---------------------------------------------------------------------------- |
|
462 // CAiPluginStateManager::ProcessStateChangeForAll() |
|
463 // ---------------------------------------------------------------------------- |
|
464 // |
|
465 void CAiPluginStateManager::ProcessStateChangeForAll( TAiStateChanges aState ) |
|
466 { |
|
467 for ( TInt i = 0; i < iStateMachines.Count(); ++i ) |
|
468 { |
|
469 iStateMachines[i]->HandleEvent( aState ); |
|
470 } |
|
471 } |
|
472 |
|
473 // ---------------------------------------------------------------------------- |
|
474 // CAiPluginStateManager::IdleFocused() |
|
475 // ---------------------------------------------------------------------------- |
|
476 // |
|
477 TBool CAiPluginStateManager::IdleFocused() const |
|
478 { |
|
479 if ( iFocusObserver ) |
|
480 { |
|
481 return ( iFocusObserver->Status() == ESMAIIdleForeground ); |
|
482 } |
|
483 |
|
484 return EFalse; |
|
485 } |
|
486 |
|
487 // ---------------------------------------------------------------------------- |
|
488 // CAiPluginStateManager::BackupOngoing() |
|
489 // ---------------------------------------------------------------------------- |
|
490 // |
|
491 TBool CAiPluginStateManager::BackupOngoing() const |
|
492 { |
|
493 if ( iBackupOperationObserver ) |
|
494 { |
|
495 return ( iBackupOperationObserver->Status() == ESMAIBackupOn ); |
|
496 } |
|
497 |
|
498 return EFalse; |
|
499 } |
|
500 |
|
501 // ---------------------------------------------------------------------------- |
|
502 // CAiPluginStateManager::LightsOn() |
|
503 // ---------------------------------------------------------------------------- |
|
504 // |
|
505 TBool CAiPluginStateManager::LightsOn() const |
|
506 { |
|
507 if ( iLightStateObserver ) |
|
508 { |
|
509 return ( iLightStateObserver->Status() == ESMAIBacklightOn ); |
|
510 } |
|
511 |
|
512 return EFalse; |
|
513 } |
|
514 |
|
515 // ---------------------------------------------------------------------------- |
|
516 // CAiPluginStateManager::CallOngoing() |
|
517 // ---------------------------------------------------------------------------- |
|
518 // |
|
519 TBool CAiPluginStateManager::CallOngoing() const |
|
520 { |
|
521 if ( iCallStateObserver ) |
|
522 { |
|
523 return ( iCallStateObserver->Status() == ESMAIInCall ); |
|
524 } |
|
525 |
|
526 return EFalse; |
|
527 } |
|
528 |
|
529 // ---------------------------------------------------------------------------- |
|
530 // CAiPluginStateManager::T1TimerCallback() |
|
531 // ---------------------------------------------------------------------------- |
|
532 // |
|
533 TInt CAiPluginStateManager::T1TimerCallback( TAny* aPtr ) |
|
534 { |
|
535 CAiPluginStateManager* self = |
|
536 static_cast< CAiPluginStateManager* >( aPtr ); |
|
537 |
|
538 __ASSERT_DEBUG( self, |
|
539 AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) ); |
|
540 |
|
541 self->iT1Timer->Cancel(); |
|
542 |
|
543 // self->ProcessStateChangeForAll( ESMAIT1Timeout ); |
|
544 |
|
545 return KErrNone; |
|
546 } |
|
547 |
|
548 // End of file |
|
549 |
|