|
1 /* |
|
2 * Copyright (c) 2009 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: The source file of the CClkSrvImpl class. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <tz.h> |
|
20 #include <centralrepository.h> |
|
21 #include <starterdomaincrkeys.h> |
|
22 #include <ecom.h> |
|
23 |
|
24 // User includes |
|
25 #include "clockserverimpl.h" |
|
26 #include "clockserver.h" |
|
27 #include "clocktimesourceinterface.h" |
|
28 #include "clocktimesourceinterface.hrh" |
|
29 #include "clockservermcclistener.h" |
|
30 #include "clocktimezoneresolver.h" |
|
31 #include "clockservermccobserver.h" |
|
32 #include "clockecomlistener.h" |
|
33 #include "clock_debug.h" |
|
34 #include "clockprivatecrkeys.h" |
|
35 |
|
36 // Constants |
|
37 const TInt KZeroIndex( 0 ); |
|
38 const TInt KSingleZone( 1 ); |
|
39 const TInt KSinglePlugin( 1 ); |
|
40 const TInt KSetValidNitz( 1 ); |
|
41 const TUid KTimeSourceInterfaceUID = { 0x200159A7 }; |
|
42 const TInt KNitzPlugin( 0x200159A5 ); |
|
43 |
|
44 // --------------------------------------------------------- |
|
45 // CClkSrvImpl::NewL |
|
46 // rest of the details are commented in the header |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 CClkSrvImpl* CClkSrvImpl::NewL( CClkSrvMain* aClkSrv ) |
|
50 { |
|
51 __PRINTS( "CClkSrvImpl::NewL - Entry" ); |
|
52 |
|
53 CClkSrvImpl* clkSrvImpl = new( ELeave ) CClkSrvImpl( aClkSrv ); |
|
54 CleanupStack::PushL( clkSrvImpl ); |
|
55 |
|
56 clkSrvImpl->ConstructL(); |
|
57 |
|
58 CleanupStack::Pop( clkSrvImpl ); |
|
59 |
|
60 __PRINTS( "CClkSrvImpl::NewL - Exit" ); |
|
61 |
|
62 return clkSrvImpl; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // CClkSrvImpl::~CClkSrvImpl |
|
67 // rest of the details are commented in the header |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 CClkSrvImpl::~CClkSrvImpl() |
|
71 { |
|
72 __PRINTS( "CClkSrvImpl::~CClkSrvImpl - Entry" ); |
|
73 |
|
74 // Cleanup |
|
75 TInt objCount( iTimeSourceObjArray.Count() ); |
|
76 |
|
77 // First iterate and destroy all the objects. |
|
78 // Only removing from the array won't free the memory. |
|
79 for( TInt index ( KZeroIndex ); index < objCount; index++ ) |
|
80 { |
|
81 CClockTimeSourceInterface* ifObject = iTimeSourceObjArray[ index ]; |
|
82 |
|
83 // Remove the object from the array. |
|
84 iTimeSourceObjArray.Remove( index ); |
|
85 |
|
86 delete ifObject; |
|
87 ifObject = NULL; |
|
88 } |
|
89 |
|
90 // Close the handle to the array. |
|
91 iTimeSourceObjArray.Close(); |
|
92 |
|
93 if( iMccListener ) |
|
94 { |
|
95 iMccListener->Stop(); |
|
96 delete iMccListener; |
|
97 iMccListener = NULL; |
|
98 } |
|
99 if( iTimeAttributes ) |
|
100 { |
|
101 delete iTimeAttributes; |
|
102 iTimeAttributes = NULL; |
|
103 } |
|
104 if( iTzResolver ) |
|
105 { |
|
106 delete iTzResolver; |
|
107 iTzResolver = NULL; |
|
108 } |
|
109 if( iClockEComListener ) |
|
110 { |
|
111 delete iClockEComListener; |
|
112 iClockEComListener = NULL; |
|
113 } |
|
114 |
|
115 __PRINTS( "CClkSrvImpl::~CClkSrvImpl - Exit" ); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // CClkSrvImpl::CClkSrvImpl |
|
120 // rest of the details are commented in the header |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 CClkSrvImpl::CClkSrvImpl( CClkSrvMain* aClkSrv ) : iClkSrv( aClkSrv ), |
|
124 iMccReceived( EFalse ), |
|
125 iPluginData( EFalse ) |
|
126 { |
|
127 __PRINTS( "CClkSrvImpl::CClkSrvImpl - Entry" ); |
|
128 |
|
129 // No implementation yet. |
|
130 |
|
131 __PRINTS( "CClkSrvImpl::CClkSrvImpl - Exit" ); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CClkSrvImpl::ConstructL |
|
136 // rest of the details are commented in the header |
|
137 // --------------------------------------------------------- |
|
138 // |
|
139 void CClkSrvImpl::ConstructL() |
|
140 { |
|
141 __PRINTS( "CClkSrvImpl::ConstructL - Entry" ); |
|
142 |
|
143 // Construct and start the mcc listener. |
|
144 iMccListener = CClkMccListener::NewL( this ); |
|
145 |
|
146 if( iMccListener ) |
|
147 { |
|
148 iMccListener->Start(); |
|
149 } |
|
150 |
|
151 // Create the resolver. |
|
152 iTzResolver = CClockTimeZoneResolver::NewL(); |
|
153 |
|
154 // Create the ECOM listener. |
|
155 TRAP_IGNORE( iClockEComListener = CClockEComListener::NewL( *this ) ); |
|
156 |
|
157 __PRINTS( "CClkSrvImpl::ConstructL - Exit" ); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------- |
|
161 // CClkSrvImpl::ActivateAllProtocols |
|
162 // rest of the details are commented in the header |
|
163 // --------------------------------------------------------- |
|
164 // |
|
165 TInt CClkSrvImpl::ActivateAllProtocolsL() |
|
166 { |
|
167 __PRINTS( "CClkSrvImpl::ActivateAllProtocolsL All- Entry" ); |
|
168 TInt returnVal( KErrNone ); |
|
169 // Array to return all implementations in an interface. |
|
170 RImplInfoPtrArray plugInArray; |
|
171 // Get the list of all implementations. |
|
172 REComSession::ListImplementationsL( KTimeSourceInterfaceUID, plugInArray ); |
|
173 |
|
174 TInt count( plugInArray.Count() ); |
|
175 // Activate all the given protocols. |
|
176 for( TInt index( KZeroIndex ); index < count; index++ ) |
|
177 { |
|
178 returnVal = ActivateProtocolL( plugInArray[ index ]->ImplementationUid().iUid ); |
|
179 } |
|
180 // Cleanup. |
|
181 plugInArray.ResetAndDestroy(); |
|
182 plugInArray.Close(); |
|
183 |
|
184 __PRINTS( "CClkSrvImpl::ActivateAllProtocolsL All- Exit" ); |
|
185 return returnVal; |
|
186 } |
|
187 // --------------------------------------------------------- |
|
188 // CClkSrvImpl::ActivateProtocol |
|
189 // rest of the details are commented in the header |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 TInt CClkSrvImpl::ActivateProtocolL( TInt aClkSrvProtocol ) |
|
193 { |
|
194 __PRINTS( "CClkSrvImpl::ActivateProtocolL - Entry" ); |
|
195 |
|
196 __PRINT( "The uid of the protocol being activated: %x", aClkSrvProtocol ); |
|
197 |
|
198 TInt returnVal( KErrNone ); |
|
199 |
|
200 // First we need to check if the plugin is already active. So we iterate through the |
|
201 // array of plugins to see if the protocol implementation id matches with any of the |
|
202 // plugin loaded. If not we load it. |
|
203 TBool alreadyActive( EFalse ); |
|
204 |
|
205 // Number of plugins loaded. |
|
206 TInt pluginCount = iTimeSourceObjArray.Count(); |
|
207 |
|
208 for( TInt index ( KZeroIndex ); index < pluginCount; index++ ) |
|
209 { |
|
210 if( aClkSrvProtocol == iTimeSourceObjArray[ index ]->GetPluginUid() ) |
|
211 { |
|
212 // We have a match, plugin is already loaded. |
|
213 alreadyActive = ETrue; |
|
214 break; |
|
215 } |
|
216 } |
|
217 |
|
218 if( alreadyActive ) |
|
219 { |
|
220 // Plugin already loaded. So return. |
|
221 __PRINTS( "Plugin is already loaded." ); |
|
222 __PRINTS( "CClkSrvImpl::ActivateProtocolL - Exit" ); |
|
223 |
|
224 return returnVal; |
|
225 } |
|
226 |
|
227 if( !alreadyActive ) |
|
228 { |
|
229 // Construct and append the object to the array. |
|
230 CClockTimeSourceInterface* timeSourceObj( NULL ); |
|
231 timeSourceObj = CClockTimeSourceInterface::NewL( TUid::Uid( aClkSrvProtocol ),this ); |
|
232 |
|
233 if( !timeSourceObj ) |
|
234 { |
|
235 // The plugin could not be loaded. |
|
236 __PRINTS( "The plugin could not be loaded." ); |
|
237 __PRINTS( "CClkSrvImpl::ActivateProtocolL - Exit" ); |
|
238 |
|
239 returnVal = KErrNotFound; |
|
240 |
|
241 return returnVal; |
|
242 } |
|
243 else |
|
244 { |
|
245 TInt automaticTimeUpdateState( KZeroIndex ); |
|
246 |
|
247 iClkSrv->GetActivePluginL( automaticTimeUpdateState ); |
|
248 // If the protocol is the default protocol for the device ,set it to On in cenrep. |
|
249 if( !automaticTimeUpdateState || KNitzPlugin == aClkSrvProtocol ) |
|
250 { |
|
251 iClkSrv->SetActivePluginL( ETrue ); |
|
252 } |
|
253 |
|
254 // The plugin was constructed. |
|
255 CleanupStack::PushL( timeSourceObj ); |
|
256 |
|
257 // Append the constructed object to the array. |
|
258 iTimeSourceObjArray.Append( timeSourceObj ); |
|
259 |
|
260 CleanupStack::Pop( timeSourceObj ); |
|
261 timeSourceObj = NULL; |
|
262 } |
|
263 } |
|
264 __PRINTS( "CClkSrvImpl::ActivateProtocolL - Exit" ); |
|
265 |
|
266 return returnVal; |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------- |
|
270 // CClkSrvImpl::IsProtocolActive |
|
271 // rest of the details are commented in the header |
|
272 // --------------------------------------------------------- |
|
273 // |
|
274 TInt CClkSrvImpl::IsProtocolActive( TBool& aIsActive, TInt aClkSrvProtocol ) |
|
275 { |
|
276 __PRINTS( "CClkSrvImpl::IsProtocolActive - Entry" ); |
|
277 __PRINT( "%x", aClkSrvProtocol ); |
|
278 |
|
279 TInt returnVal( KErrNone ); |
|
280 |
|
281 aIsActive = EFalse; |
|
282 |
|
283 // Get the count of objects. |
|
284 TInt arrayCount = iTimeSourceObjArray.Count(); |
|
285 |
|
286 // Browse the array of active plugins to check if the input plugin exists |
|
287 for(TInt index ( KZeroIndex ); index < arrayCount; index++ ) |
|
288 { |
|
289 if( aClkSrvProtocol == iTimeSourceObjArray[ index ]->GetPluginUid() ) |
|
290 { |
|
291 // We have a match, plugin is loaded. |
|
292 aIsActive = ETrue; |
|
293 |
|
294 break; |
|
295 } |
|
296 } |
|
297 |
|
298 __PRINTS( "CClkSrvImpl::IsProtocolActive - Exit" ); |
|
299 |
|
300 return returnVal; |
|
301 } |
|
302 // --------------------------------------------------------- |
|
303 // CClkSrvImpl::DeActivateAllProtocols |
|
304 // rest of the details are commented in the header |
|
305 // --------------------------------------------------------- |
|
306 // |
|
307 TInt CClkSrvImpl::DeActivateAllProtocolsL() |
|
308 { |
|
309 __PRINTS( "CClkSrvImpl::DeActivateAllProtocolsL All- Entry" ); |
|
310 |
|
311 TInt returnVal( KErrNone ); |
|
312 // Array to return all implementations in an interface. |
|
313 RImplInfoPtrArray plugInArray; |
|
314 |
|
315 // Get the list of all implementations. |
|
316 REComSession::ListImplementationsL( KTimeSourceInterfaceUID, plugInArray ); |
|
317 |
|
318 // Set the cendrep key for Automatic time update status to off. |
|
319 TInt automaticTimeUpdateState( KZeroIndex ); |
|
320 |
|
321 iClkSrv->GetActivePluginL( automaticTimeUpdateState ); |
|
322 |
|
323 if( automaticTimeUpdateState ) |
|
324 { |
|
325 iClkSrv->SetActivePluginL( EFalse ); |
|
326 } |
|
327 |
|
328 // Deactivate all the given protocols. |
|
329 for( TInt index( KZeroIndex ); index < plugInArray.Count(); index++ ) |
|
330 { |
|
331 returnVal = DeActivateProtocolL( plugInArray[ index ]->ImplementationUid().iUid ); |
|
332 } |
|
333 // Cleanup. |
|
334 plugInArray.ResetAndDestroy(); |
|
335 plugInArray.Close(); |
|
336 |
|
337 __PRINTS( "CClkSrvImpl::DeActivateAllProtocolsL All- Exit" ); |
|
338 return returnVal; |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------- |
|
342 // CClkSrvImpl::DeActivateProtocolL |
|
343 // rest of the details are commented in the header |
|
344 // --------------------------------------------------------- |
|
345 // |
|
346 TInt CClkSrvImpl::DeActivateProtocolL( TInt aClkSrvProtocol ) |
|
347 { |
|
348 __PRINTS( "CClkSrvImpl::DeActivateProtocolL - Entry" ); |
|
349 __PRINT( "The uid of the protocol being deactivated :%x", aClkSrvProtocol ); |
|
350 |
|
351 TInt returnVal( KErrNotFound ); |
|
352 |
|
353 // Get the count of objects. |
|
354 TInt arrayCount = iTimeSourceObjArray.Count(); |
|
355 |
|
356 |
|
357 |
|
358 // Browse every active plugin object to find the match. |
|
359 for( TInt index( KZeroIndex ) ; index < arrayCount; index++ ) |
|
360 { |
|
361 if( aClkSrvProtocol == iTimeSourceObjArray[ index ]->GetPluginUid() ) |
|
362 { |
|
363 // set the state it to Off in cenrep |
|
364 TInt automaticTimeUpdateState( KZeroIndex ); |
|
365 iClkSrv->GetActivePluginL( automaticTimeUpdateState ); |
|
366 |
|
367 if( ( automaticTimeUpdateState ) && ( KSinglePlugin == arrayCount ) ) |
|
368 { |
|
369 iClkSrv->SetActivePluginL( EFalse ); |
|
370 } |
|
371 // We have a match, plugin is loaded. Now destroy it. |
|
372 CClockTimeSourceInterface* ifObject = iTimeSourceObjArray[ index ]; |
|
373 CleanupStack::PushL( ifObject ); |
|
374 |
|
375 // Remove from the array. |
|
376 iTimeSourceObjArray.Remove( index ); |
|
377 |
|
378 // Free the memory. |
|
379 CleanupStack::PopAndDestroy( ifObject ); |
|
380 |
|
381 returnVal = KErrNone; |
|
382 break; |
|
383 } |
|
384 } |
|
385 __PRINTS( "CClkSrvImpl::DeActivateProtocolL - Exit" ); |
|
386 |
|
387 return returnVal; |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------- |
|
391 // CClkSrvImpl::GetProtocolInformationL() |
|
392 // rest of the details are commented in the header |
|
393 // --------------------------------------------------------- |
|
394 // |
|
395 TInt CClkSrvImpl::GetProtocolInformationL( STimeAttributes& aTimeInformation ) |
|
396 { |
|
397 __PRINTS( "CClkSrvImpl::GetProtocolInformationL - Entry" ); |
|
398 |
|
399 TInt returnValue( KErrNotFound ); |
|
400 |
|
401 if( iTimeAttributes ) |
|
402 { |
|
403 returnValue = KErrNone; |
|
404 |
|
405 // Assign the time information. |
|
406 aTimeInformation = *iTimeAttributes; |
|
407 } |
|
408 |
|
409 __PRINTS( "CClkSrvImpl::GetProtocolInformationL - Exit" ); |
|
410 |
|
411 return returnValue; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------- |
|
415 // CClkSrvImpl::GetCurrentMccL() |
|
416 // rest of the details are commented in the header |
|
417 // --------------------------------------------------------- |
|
418 // |
|
419 TInt CClkSrvImpl::GetCurrentMccL( TInt& aCurrentMcc ) |
|
420 { |
|
421 __PRINTS( "CClkSrvImpl::GetCurrentMccL - Entry" ); |
|
422 |
|
423 TInt returnValue( KErrNotFound ); |
|
424 |
|
425 if( iMccReceived ) |
|
426 { |
|
427 TLex currentMcc; |
|
428 currentMcc.Assign( iMcc ); |
|
429 |
|
430 // Return the value |
|
431 currentMcc.Val( aCurrentMcc ); |
|
432 |
|
433 returnValue = KErrNone; |
|
434 |
|
435 __PRINT( "Current MCC - %d", aCurrentMcc ); |
|
436 } |
|
437 |
|
438 __PRINTS( "CClkSrvImpl::GetCurrentMccL - Exit" ); |
|
439 |
|
440 return returnValue; |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------- |
|
444 // CClkSrvImpl::GetCurrentTimeZoneIdL() |
|
445 // rest of the details are commented in the header |
|
446 // --------------------------------------------------------- |
|
447 // |
|
448 TInt CClkSrvImpl::GetCurrentTimeZoneIdL( TInt& aCurrentTimeZoneId ) |
|
449 { |
|
450 __PRINTS( "CClkSrvImpl::GetCurrentTimeZoneIdL - Entry" ); |
|
451 |
|
452 TInt returnValue( KErrNotFound ); |
|
453 |
|
454 if( 0 != iTimeZoneId ) |
|
455 { |
|
456 // Assign the value |
|
457 aCurrentTimeZoneId = iTimeZoneId; |
|
458 |
|
459 returnValue = KErrNone; |
|
460 } |
|
461 |
|
462 __PRINT( "Current timezone ID: %d", iTimeZoneId ); |
|
463 |
|
464 __PRINTS( "CClkSrvImpl::GetCurrentTimeZoneIdL - Exit" ); |
|
465 |
|
466 return returnValue; |
|
467 } |
|
468 |
|
469 // --------------------------------------------------------- |
|
470 // CClkSrvImpl::IsAutoTimeUpdateOn |
|
471 // rest of the details are commented in the header |
|
472 // --------------------------------------------------------- |
|
473 // |
|
474 TInt CClkSrvImpl::IsAutoTimeUpdateOn( TBool& aEnabled ) |
|
475 { |
|
476 __PRINTS( "CClkSrvImpl::IsAutoTimeUpdateOn - Entry" ); |
|
477 |
|
478 TInt returnValue( KErrNone ); |
|
479 |
|
480 // If the array has any items, it means atleast one of the protocols is active. |
|
481 aEnabled = iTimeSourceObjArray.Count() ? ETrue : EFalse; |
|
482 |
|
483 __PRINTS( "CClkSrvImpl::IsAutoTimeUpdateOn - Exit" ); |
|
484 |
|
485 return returnValue; |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------- |
|
489 // CClkSrvImpl::NotifyTimeChangeL() |
|
490 // rest of the details are commented in the header |
|
491 // --------------------------------------------------------- |
|
492 // |
|
493 void CClkSrvImpl::NotifyTimeChangeL( CClockTimeSourceInterface& aPluginImpl ) |
|
494 { |
|
495 __PRINTS( "CClkSrvImpl::NotifyTimeChangeL - Entry" ); |
|
496 |
|
497 // Construct the time attributes holder struct object. |
|
498 if( !iTimeAttributes ) |
|
499 { |
|
500 TRAPD( errVal, iTimeAttributes = new( ELeave ) STimeAttributes ); |
|
501 if( KErrNone != errVal ) |
|
502 { |
|
503 __PRINTS( "Could not construct time attributes holder" ); |
|
504 |
|
505 __PRINTS( "CClkSrvImpl::NotifyTimeChangeL - Exit" ); |
|
506 |
|
507 return; |
|
508 } |
|
509 } |
|
510 |
|
511 // Get all the information related to the plugin. |
|
512 // The UTC time. |
|
513 TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EUTCTime, iTimeAttributes ) ); |
|
514 // The default offset. |
|
515 TRAP_IGNORE( aPluginImpl.GetTimeInformationL( ETZOffset, iTimeAttributes ) ); |
|
516 // The dst offset. |
|
517 TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EDSTOffset, iTimeAttributes ) ); |
|
518 |
|
519 // Set a flag saying we have plugin data. |
|
520 iPluginData = ETrue; |
|
521 |
|
522 // Get the first boot status from cenrep. If it is the first boot, clockserver will not update the time. |
|
523 TBool staleBoot( EFalse ); |
|
524 |
|
525 CRepository* cenRep( NULL ); |
|
526 |
|
527 TRAPD( errorVal, cenRep = CRepository::NewL( KCRUidStartup ) ); |
|
528 |
|
529 if( errorVal == KErrNone ) |
|
530 { |
|
531 errorVal = cenRep->Get( KStartupFirstBoot, staleBoot ); |
|
532 } |
|
533 |
|
534 // Cleanup. |
|
535 delete cenRep; |
|
536 cenRep = NULL; |
|
537 |
|
538 if( iMccReceived ) |
|
539 { |
|
540 __PRINTS( "We have already recieved the MCC" ); |
|
541 |
|
542 // Try to resolve the timezone id with the data that we have recieved. |
|
543 TInt timezoneId; |
|
544 TRAP_IGNORE( TInt errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, iMcc, timezoneId ) ); |
|
545 |
|
546 __PRINT( "CClkSrvImpl::NotifyTimeChangeL - timeZoneId: %d", timezoneId ); |
|
547 |
|
548 __PRINT( "NotifyTimeChangeL::timezoneId : %d", timezoneId); |
|
549 |
|
550 // If a match is found, set the timezone and the time. |
|
551 if( KErrNone == errorVal ) |
|
552 { |
|
553 // Save the timezone Id. |
|
554 iTimeZoneId = timezoneId; |
|
555 |
|
556 RTz tz; |
|
557 User::LeaveIfError( tz.Connect() ); |
|
558 CleanupClosePushL( tz ); |
|
559 |
|
560 // Get current DST zone Id |
|
561 CTzId* currentCTzId = tz.GetTimeZoneIdL(); |
|
562 CleanupStack::PushL( currentCTzId ); |
|
563 |
|
564 if( KInvalidTimeZoneId != timezoneId ) |
|
565 { |
|
566 // A valid new zone was found successfully |
|
567 |
|
568 // Update the key for ValidNitz for the first boot |
|
569 if(!staleBoot) |
|
570 { |
|
571 TInt validNitz( KSetValidNitz ); |
|
572 CRepository* cenRep( NULL ); |
|
573 |
|
574 TRAPD( errorVal, cenRep = CRepository::NewL( KCRUidNitz ) ); |
|
575 if( errorVal == KErrNone ) |
|
576 { |
|
577 errorVal = cenRep->Set( KValidNitz, validNitz ); |
|
578 } |
|
579 // Cleanup. |
|
580 delete cenRep; |
|
581 cenRep = NULL; |
|
582 } |
|
583 |
|
584 CTzId* newTzId = CTzId::NewL( timezoneId ); |
|
585 CleanupStack::PushL( newTzId ); |
|
586 |
|
587 __PRINT( "NotifyTimeChangeL::currentCTzId : %d", currentCTzId->TimeZoneNumericID() ); |
|
588 |
|
589 __PRINT( "NotifyTimeChangeL::newTzId : %d", newTzId->TimeZoneNumericID() ); |
|
590 |
|
591 if( *newTzId != *currentCTzId ) |
|
592 { |
|
593 // The new zone is different than the current one |
|
594 // GOAL 3: Set the DST zone of the device |
|
595 //if( staleBoot ) |
|
596 //{ |
|
597 __PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." ); |
|
598 |
|
599 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
|
600 // } |
|
601 } |
|
602 |
|
603 CleanupStack::PopAndDestroy( newTzId ); |
|
604 } |
|
605 |
|
606 CleanupStack::PopAndDestroy( currentCTzId ); |
|
607 CleanupStack::PopAndDestroy( &tz ); |
|
608 |
|
609 // Time sent by nw is UTC |
|
610 TTime nwUtcTime( iTimeAttributes->iUtcDateTime ); |
|
611 |
|
612 // Set the UTC time only. This is being done because with the UTC time, |
|
613 // before the time is being set, the dst properties for the timezone are being checked. |
|
614 // If its not the first boot, then set the time. |
|
615 //if( staleBoot ) |
|
616 // { |
|
617 __PRINTS( "Not the first boot. Setting the UTC time." ); |
|
618 |
|
619 TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) ); |
|
620 // } |
|
621 } |
|
622 |
|
623 // Reset the flags. |
|
624 iPluginData = EFalse; |
|
625 } |
|
626 else |
|
627 { |
|
628 __PRINTS( "MCC has not yet been recieved. Trying to resolve with offset only." ); |
|
629 |
|
630 // Handle the case. |
|
631 // 1. Use the plugin data and set the time. |
|
632 // 2. Use the offset in the plugindata or any available to deduce the timezone id. |
|
633 |
|
634 // Try to resolve the timezone id with the data that we have recieved. |
|
635 TInt timezoneId; |
|
636 const TBuf< 4 > invalidMCC( KInvalidMCC ); |
|
637 TRAP_IGNORE( TInt errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, invalidMCC, timezoneId ) ); |
|
638 |
|
639 if( KErrNone == errorVal ) |
|
640 { |
|
641 RTz tz; |
|
642 User::LeaveIfError( tz.Connect() ); |
|
643 CleanupClosePushL( tz ); |
|
644 |
|
645 // Get current DST zone Id |
|
646 CTzId* currentCTzId = tz.GetTimeZoneIdL(); |
|
647 CleanupStack::PushL( currentCTzId ); |
|
648 |
|
649 if( KInvalidTimeZoneId != timezoneId ) |
|
650 { |
|
651 // A valid new zone was found successfully |
|
652 |
|
653 // Update the key for ValidNitz for the first boot |
|
654 if(!staleBoot) |
|
655 { |
|
656 TInt validNitz( KSetValidNitz ); |
|
657 CRepository* cenRep( NULL ); |
|
658 |
|
659 TRAPD( errorVal, cenRep = CRepository::NewL( KCRUidNitz ) ); |
|
660 if( errorVal == KErrNone ) |
|
661 { |
|
662 errorVal = cenRep->Set( KValidNitz, validNitz ); |
|
663 } |
|
664 // Cleanup. |
|
665 delete cenRep; |
|
666 cenRep = NULL; |
|
667 } |
|
668 |
|
669 CTzId* newTzId = CTzId::NewL( timezoneId ); |
|
670 CleanupStack::PushL( newTzId ); |
|
671 |
|
672 if( *newTzId != *currentCTzId ) |
|
673 { |
|
674 // The new zone is different than the current one |
|
675 // GOAL 3: Set the DST zone of the device |
|
676 // If firstboot then don't set the time. |
|
677 //if( staleBoot ) |
|
678 // { |
|
679 __PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." ); |
|
680 |
|
681 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
|
682 // } |
|
683 } |
|
684 CleanupStack::PopAndDestroy( newTzId ); |
|
685 } |
|
686 CleanupStack::PopAndDestroy( currentCTzId ); |
|
687 CleanupStack::PopAndDestroy( &tz ); |
|
688 |
|
689 |
|
690 // Set the home time only and leave the zone as it is. |
|
691 TTime nwUtcTime( iTimeAttributes->iUtcDateTime ); |
|
692 |
|
693 // Set the UTC time only. This is being done because with the UTC time, |
|
694 // before the time is being set, the dst properties for the timezone are being checked. |
|
695 // Set the time only if its not the first boot. |
|
696 //if( staleBoot ) |
|
697 // { |
|
698 __PRINTS( "Not the first boot. Setting the UTC time." ); |
|
699 |
|
700 TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) ); |
|
701 // } |
|
702 } |
|
703 } |
|
704 __PRINTS( "Notifying the timechange to client" ); |
|
705 |
|
706 // Notify the sessions about the change. |
|
707 iClkSrv->NotifyAboutChange( EComponentTime, aPluginImpl.GetPluginUid(), KErrNone ); |
|
708 |
|
709 __PRINTS( "CClkSrvImpl::NotifyTimeChangeL - Exit" ); |
|
710 } |
|
711 |
|
712 // --------------------------------------------------------- |
|
713 // CClkSrvImpl::NotifyMccChange() |
|
714 // rest of the details are commented in the header |
|
715 // --------------------------------------------------------- |
|
716 // |
|
717 void CClkSrvImpl::NotifyMccChangeL() |
|
718 { |
|
719 __PRINTS( "CClkSrvImpl::NotifyMccChangeL - Entry" ); |
|
720 |
|
721 // We have the mobile country code. Get it from the listener. |
|
722 iMccListener->GetCurrentMcc( iMcc ); |
|
723 |
|
724 // Set mcc received flag. |
|
725 iMccReceived = ETrue; |
|
726 |
|
727 // We should change the timezone only if user has chosen to update time automatically. |
|
728 if( iTimeSourceObjArray.Count() ) |
|
729 { |
|
730 __PRINTS( "Automatic time update is ON. Trying to resolve the timezone." ); |
|
731 |
|
732 // We have atleast one protocol active. |
|
733 // Lets see if we can narrow down to a single timezone with the MCC recieved. |
|
734 RArray< CTzId > tzIdArray; |
|
735 |
|
736 // Try and fetch the timezone ID using the MCC recieved. |
|
737 TRAP_IGNORE( iTzResolver->TzIdFromMccL( iMcc, tzIdArray, KInvalidTimeZoneId ) ); |
|
738 |
|
739 // Code to check if its the first boot. |
|
740 // Get the first boot status from cenrep. If it is the first boot, clockserver will not update the time. |
|
741 TBool staleBoot( EFalse ); |
|
742 |
|
743 CRepository* cenRep( NULL ); |
|
744 |
|
745 TRAPD( errorVal, cenRep = CRepository::NewL( KCRUidStartup ) ); |
|
746 |
|
747 if( errorVal == KErrNone ) |
|
748 { |
|
749 errorVal = cenRep->Get( KStartupFirstBoot, staleBoot ); |
|
750 } |
|
751 |
|
752 // Cleanup |
|
753 delete cenRep; |
|
754 cenRep = NULL; |
|
755 |
|
756 // A single matching timezone was found. Set it as the default one. |
|
757 if( KSingleZone == tzIdArray.Count() ) |
|
758 { |
|
759 RTz tz; |
|
760 User::LeaveIfError( tz.Connect() ); |
|
761 CleanupClosePushL( tz ); |
|
762 |
|
763 // Get current DST zone Id |
|
764 CTzId* currentCTzId = tz.GetTimeZoneIdL(); |
|
765 CleanupStack::PushL( currentCTzId ); |
|
766 |
|
767 // Fetch the first timezone |
|
768 TInt timezoneID = tzIdArray[ KZeroIndex ].TimeZoneNumericID(); |
|
769 |
|
770 if( KInvalidTimeZoneId != timezoneID ) |
|
771 { |
|
772 // A valid new zone was found successfully |
|
773 CTzId* newTzId = CTzId::NewL( timezoneID ); |
|
774 CleanupStack::PushL( newTzId ); |
|
775 |
|
776 iTimeZoneId = timezoneID ; |
|
777 |
|
778 if( *newTzId != *currentCTzId ) |
|
779 { |
|
780 // The new zone is different than the current one |
|
781 // Set the DST zone of the device |
|
782 // Set the zone only for subsequent boots. |
|
783 if( staleBoot ) |
|
784 { |
|
785 __PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." ); |
|
786 |
|
787 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
|
788 } |
|
789 } |
|
790 CleanupStack::PopAndDestroy( newTzId ); |
|
791 } |
|
792 CleanupStack::PopAndDestroy( currentCTzId ); |
|
793 CleanupStack::PopAndDestroy( &tz ); |
|
794 } |
|
795 } |
|
796 |
|
797 // Notify the sessions about the change in mcc. |
|
798 iClkSrv->NotifyAboutChange( EComponentMcc, 0, KErrNone ); |
|
799 |
|
800 __PRINTS( "CClkSrvImpl::NotifyMccChangeL - Exit" ); |
|
801 } |
|
802 |
|
803 // --------------------------------------------------------- |
|
804 // CClkSrvImpl::NotifyPluginInstallUninstallL() |
|
805 // rest of the details are commented in the header |
|
806 // --------------------------------------------------------- |
|
807 // |
|
808 void CClkSrvImpl::NotifyPluginInstallUninstallL( const CImplementationInformation& aImplInfo, TBool /*aInstalled*/ ) |
|
809 { |
|
810 __PRINTS( "CClkSrvImpl::NotifyPluginInstallUninstallL - Entry" ); |
|
811 |
|
812 // Get the plugin UID which was modified. |
|
813 TUid pluginUid( aImplInfo.ImplementationUid() ); |
|
814 TBool pluginActive( EFalse ); |
|
815 |
|
816 // Check if the protocol was already active. |
|
817 IsProtocolActive( pluginActive, pluginUid.iUid ); |
|
818 |
|
819 // If the plugin was not already active, then we dont have to bother, |
|
820 // since the clockserver state is not affected by the change. |
|
821 if( !pluginActive ) |
|
822 { |
|
823 __PRINTS( "The plugin is not active. Check if Automatic time update is on,if True activate the plugin." ); |
|
824 |
|
825 TBool timeUpdateOn( EFalse ); |
|
826 IsAutoTimeUpdateOn( timeUpdateOn ); |
|
827 if( timeUpdateOn ) |
|
828 { |
|
829 ActivateProtocolL( pluginUid.iUid ); |
|
830 } |
|
831 |
|
832 __PRINTS( "CClkSrvImpl::NotifyPluginInstallUninstallL - Exit" ); |
|
833 |
|
834 return; |
|
835 } |
|
836 |
|
837 // If the plugin was active, then deactivate it so that we dont have any older references. |
|
838 TInt returnVal( DeActivateProtocolL( pluginUid.iUid ) ); |
|
839 |
|
840 if( KErrNone == returnVal ) |
|
841 { |
|
842 __PRINTS( "Closing the ECom session" ); |
|
843 |
|
844 // Close the REComSession. This is added as a fix for the CClockEcomResolver component where |
|
845 // call to this ensures that the plugin and its associated DLL is removed from the memory. |
|
846 REComSession::FinalClose(); |
|
847 } |
|
848 |
|
849 // Activate the protocol again. This is required because - |
|
850 // 1. If the plugin was a upgrade and it was uninstalled, we need to activate the older version. |
|
851 // 2. If a new plugin was installed, we need to activate the newer version of the plugin. |
|
852 ActivateProtocolL( pluginUid.iUid ); |
|
853 |
|
854 __PRINTS( "CClkSrvImpl::NotifyPluginInstallUninstallL - Exit" ); |
|
855 } |
|
856 |
|
857 // End of file |