29 #include "clockservermcclistener.h" |
29 #include "clockservermcclistener.h" |
30 #include "clocktimezoneresolver.h" |
30 #include "clocktimezoneresolver.h" |
31 #include "clockservermccobserver.h" |
31 #include "clockservermccobserver.h" |
32 #include "clockecomlistener.h" |
32 #include "clockecomlistener.h" |
33 #include "clock_debug.h" |
33 #include "clock_debug.h" |
34 #include "clockprivatecrkeys.h" |
|
35 |
34 |
36 // Constants |
35 // Constants |
37 const TInt KZeroIndex( 0 ); |
36 const TInt KZeroIndex( 0 ); |
38 const TInt KSingleZone( 1 ); |
37 const TInt KSingleZone( 1 ); |
39 const TInt KSinglePlugin( 1 ); |
38 const TInt KSinglePlugin( 1 ); |
517 TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EDSTOffset, iTimeAttributes ) ); |
516 TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EDSTOffset, iTimeAttributes ) ); |
518 |
517 |
519 // Set a flag saying we have plugin data. |
518 // Set a flag saying we have plugin data. |
520 iPluginData = ETrue; |
519 iPluginData = ETrue; |
521 |
520 |
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 ) |
521 if( iMccReceived ) |
539 { |
522 { |
540 __PRINTS( "We have already recieved the MCC" ); |
523 __PRINTS( "We have already recieved the MCC" ); |
541 |
524 |
542 // Try to resolve the timezone id with the data that we have recieved. |
525 // Try to resolve the timezone id with the data that we have recieved. |
543 TInt timezoneId; |
526 TInt timezoneId; |
544 TRAP_IGNORE( TInt errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, iMcc, timezoneId ) ); |
527 TInt errorVal; |
|
528 TRAP_IGNORE( errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, iMcc, timezoneId ) ); |
545 |
529 |
546 __PRINT( "CClkSrvImpl::NotifyTimeChangeL - timeZoneId: %d", timezoneId ); |
530 __PRINT( "CClkSrvImpl::NotifyTimeChangeL - timeZoneId: %d", timezoneId ); |
547 |
531 |
548 __PRINT( "NotifyTimeChangeL::timezoneId : %d", timezoneId); |
532 __PRINT( "NotifyTimeChangeL::timezoneId : %d", timezoneId); |
549 |
533 |
562 CleanupStack::PushL( currentCTzId ); |
546 CleanupStack::PushL( currentCTzId ); |
563 |
547 |
564 if( KInvalidTimeZoneId != timezoneId ) |
548 if( KInvalidTimeZoneId != timezoneId ) |
565 { |
549 { |
566 // A valid new zone was found successfully |
550 // 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 = |
|
575 CRepository::NewL( TUid::Uid(KCRUidNitz) ) ); |
|
576 if( errorVal == KErrNone ) |
|
577 { |
|
578 errorVal = cenRep->Set( KValidNitz, validNitz ); |
|
579 } |
|
580 // Cleanup. |
|
581 delete cenRep; |
|
582 cenRep = NULL; |
|
583 } |
|
584 |
|
585 CTzId* newTzId = CTzId::NewL( timezoneId ); |
551 CTzId* newTzId = CTzId::NewL( timezoneId ); |
586 CleanupStack::PushL( newTzId ); |
552 CleanupStack::PushL( newTzId ); |
587 |
553 |
588 __PRINT( "NotifyTimeChangeL::currentCTzId : %d", currentCTzId->TimeZoneNumericID() ); |
554 __PRINT( "NotifyTimeChangeL::currentCTzId : %d", currentCTzId->TimeZoneNumericID() ); |
589 |
555 |
591 |
557 |
592 if( *newTzId != *currentCTzId ) |
558 if( *newTzId != *currentCTzId ) |
593 { |
559 { |
594 // The new zone is different than the current one |
560 // The new zone is different than the current one |
595 // GOAL 3: Set the DST zone of the device |
561 // GOAL 3: Set the DST zone of the device |
596 //if( staleBoot ) |
562 __PRINTS( "Timezone ID is different. Setting the zone." ); |
597 //{ |
|
598 __PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." ); |
|
599 |
563 |
600 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
564 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
601 // } |
|
602 } |
565 } |
603 |
566 |
604 CleanupStack::PopAndDestroy( newTzId ); |
567 CleanupStack::PopAndDestroy( newTzId ); |
605 } |
568 } |
606 |
569 |
611 TTime nwUtcTime( iTimeAttributes->iUtcDateTime ); |
574 TTime nwUtcTime( iTimeAttributes->iUtcDateTime ); |
612 |
575 |
613 // Set the UTC time only. This is being done because with the UTC time, |
576 // Set the UTC time only. This is being done because with the UTC time, |
614 // before the time is being set, the dst properties for the timezone are being checked. |
577 // before the time is being set, the dst properties for the timezone are being checked. |
615 // If its not the first boot, then set the time. |
578 // If its not the first boot, then set the time. |
616 //if( staleBoot ) |
579 __PRINTS( "Setting the UTC time." ); |
617 // { |
|
618 __PRINTS( "Not the first boot. Setting the UTC time." ); |
|
619 |
580 |
620 TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) ); |
581 TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) ); |
621 // } |
|
622 } |
582 } |
623 |
583 |
624 // Reset the flags. |
584 // Reset the flags. |
625 iPluginData = EFalse; |
585 iPluginData = EFalse; |
626 } |
586 } |
632 // 1. Use the plugin data and set the time. |
592 // 1. Use the plugin data and set the time. |
633 // 2. Use the offset in the plugindata or any available to deduce the timezone id. |
593 // 2. Use the offset in the plugindata or any available to deduce the timezone id. |
634 |
594 |
635 // Try to resolve the timezone id with the data that we have recieved. |
595 // Try to resolve the timezone id with the data that we have recieved. |
636 TInt timezoneId; |
596 TInt timezoneId; |
|
597 TInt errorVal; |
637 const TBuf< 4 > invalidMCC( KInvalidMCC ); |
598 const TBuf< 4 > invalidMCC( KInvalidMCC ); |
638 TRAP_IGNORE( TInt errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, invalidMCC, timezoneId ) ); |
599 TRAP_IGNORE( errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, invalidMCC, timezoneId ) ); |
639 |
600 |
640 if( KErrNone == errorVal ) |
601 if( KErrNone == errorVal ) |
641 { |
602 { |
642 RTz tz; |
603 RTz tz; |
643 User::LeaveIfError( tz.Connect() ); |
604 User::LeaveIfError( tz.Connect() ); |
648 CleanupStack::PushL( currentCTzId ); |
609 CleanupStack::PushL( currentCTzId ); |
649 |
610 |
650 if( KInvalidTimeZoneId != timezoneId ) |
611 if( KInvalidTimeZoneId != timezoneId ) |
651 { |
612 { |
652 // A valid new zone was found successfully |
613 // A valid new zone was found successfully |
653 |
|
654 // Update the key for ValidNitz for the first boot |
|
655 if(!staleBoot) |
|
656 { |
|
657 TInt validNitz( KSetValidNitz ); |
|
658 CRepository* cenRep( NULL ); |
|
659 |
|
660 TRAPD( errorVal, cenRep = |
|
661 CRepository::NewL( TUid::Uid(KCRUidNitz) ) ); |
|
662 if( errorVal == KErrNone ) |
|
663 { |
|
664 errorVal = cenRep->Set( KValidNitz, validNitz ); |
|
665 } |
|
666 // Cleanup. |
|
667 delete cenRep; |
|
668 cenRep = NULL; |
|
669 } |
|
670 |
|
671 CTzId* newTzId = CTzId::NewL( timezoneId ); |
614 CTzId* newTzId = CTzId::NewL( timezoneId ); |
672 CleanupStack::PushL( newTzId ); |
615 CleanupStack::PushL( newTzId ); |
673 |
616 |
674 if( *newTzId != *currentCTzId ) |
617 if( *newTzId != *currentCTzId ) |
675 { |
618 { |
676 // The new zone is different than the current one |
619 // The new zone is different than the current one |
677 // GOAL 3: Set the DST zone of the device |
620 // GOAL 3: Set the DST zone of the device |
678 // If firstboot then don't set the time. |
621 // If firstboot then don't set the time. |
679 //if( staleBoot ) |
622 __PRINTS( "The timezone ID is different. Setting the zone." ); |
680 // { |
|
681 __PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." ); |
|
682 |
623 |
683 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
624 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
684 // } |
|
685 } |
625 } |
686 CleanupStack::PopAndDestroy( newTzId ); |
626 CleanupStack::PopAndDestroy( newTzId ); |
687 } |
627 } |
688 CleanupStack::PopAndDestroy( currentCTzId ); |
628 CleanupStack::PopAndDestroy( currentCTzId ); |
689 CleanupStack::PopAndDestroy( &tz ); |
629 CleanupStack::PopAndDestroy( &tz ); |
693 TTime nwUtcTime( iTimeAttributes->iUtcDateTime ); |
633 TTime nwUtcTime( iTimeAttributes->iUtcDateTime ); |
694 |
634 |
695 // Set the UTC time only. This is being done because with the UTC time, |
635 // Set the UTC time only. This is being done because with the UTC time, |
696 // before the time is being set, the dst properties for the timezone are being checked. |
636 // before the time is being set, the dst properties for the timezone are being checked. |
697 // Set the time only if its not the first boot. |
637 // Set the time only if its not the first boot. |
698 //if( staleBoot ) |
638 __PRINTS( "Setting the UTC time." ); |
699 // { |
639 |
700 __PRINTS( "Not the first boot. Setting the UTC time." ); |
640 TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) ); |
701 |
|
702 TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) ); |
|
703 // } |
|
704 } |
641 } |
705 } |
642 } |
706 __PRINTS( "Notifying the timechange to client" ); |
643 __PRINTS( "Notifying the timechange to client" ); |
707 |
644 |
708 // Notify the sessions about the change. |
645 // Notify the sessions about the change. |
736 RArray< CTzId > tzIdArray; |
673 RArray< CTzId > tzIdArray; |
737 |
674 |
738 // Try and fetch the timezone ID using the MCC recieved. |
675 // Try and fetch the timezone ID using the MCC recieved. |
739 TRAP_IGNORE( iTzResolver->TzIdFromMccL( iMcc, tzIdArray, KInvalidTimeZoneId ) ); |
676 TRAP_IGNORE( iTzResolver->TzIdFromMccL( iMcc, tzIdArray, KInvalidTimeZoneId ) ); |
740 |
677 |
741 // Code to check if its the first boot. |
|
742 // Get the first boot status from cenrep. If it is the first boot, clockserver will not update the time. |
|
743 TBool staleBoot( EFalse ); |
|
744 |
|
745 CRepository* cenRep( NULL ); |
|
746 |
|
747 TRAPD( errorVal, cenRep = CRepository::NewL( KCRUidStartup ) ); |
|
748 |
|
749 if( errorVal == KErrNone ) |
|
750 { |
|
751 errorVal = cenRep->Get( KStartupFirstBoot, staleBoot ); |
|
752 } |
|
753 |
|
754 // Cleanup |
|
755 delete cenRep; |
|
756 cenRep = NULL; |
|
757 |
|
758 // A single matching timezone was found. Set it as the default one. |
678 // A single matching timezone was found. Set it as the default one. |
759 if( KSingleZone == tzIdArray.Count() ) |
679 if( KSingleZone == tzIdArray.Count() ) |
760 { |
680 { |
761 RTz tz; |
681 RTz tz; |
762 User::LeaveIfError( tz.Connect() ); |
682 User::LeaveIfError( tz.Connect() ); |
780 if( *newTzId != *currentCTzId ) |
700 if( *newTzId != *currentCTzId ) |
781 { |
701 { |
782 // The new zone is different than the current one |
702 // The new zone is different than the current one |
783 // Set the DST zone of the device |
703 // Set the DST zone of the device |
784 // Set the zone only for subsequent boots. |
704 // Set the zone only for subsequent boots. |
785 if( staleBoot ) |
705 __PRINTS( "The timezone ID is different. Setting the zone." ); |
786 { |
|
787 __PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." ); |
|
788 |
706 |
789 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
707 TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) ); |
790 } |
|
791 } |
708 } |
792 CleanupStack::PopAndDestroy( newTzId ); |
709 CleanupStack::PopAndDestroy( newTzId ); |
793 } |
710 } |
794 CleanupStack::PopAndDestroy( currentCTzId ); |
711 CleanupStack::PopAndDestroy( currentCTzId ); |
795 CleanupStack::PopAndDestroy( &tz ); |
712 CleanupStack::PopAndDestroy( &tz ); |