clock/clockengines/clockserver/server/src/clockserverimpl.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    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 );
    40 const TInt KSetValidNitz( 1 );
       
    41 const TUid KTimeSourceInterfaceUID = { 0x200159A7 };
    39 const TUid KTimeSourceInterfaceUID = { 0x200159A7 };
    42 const TInt KNitzPlugin( 0x200159A5 );
    40 const TInt KNitzPlugin( 0x200159A5 );
    43 
    41 
    44 // ---------------------------------------------------------
    42 // ---------------------------------------------------------
    45 // CClkSrvImpl::NewL
    43 // CClkSrvImpl::NewL
   506 		    
   504 		    
   507 		    return;
   505 		    return;
   508 		    }
   506 		    }
   509 		}
   507 		}
   510 	
   508 	
       
   509 	// Initialise the attributes to null.
       
   510 	TTime invalidTime( 0 );
       
   511 	iTimeAttributes->iDstOffset = TTimeIntervalMinutes( 0 );
       
   512 	iTimeAttributes->iTimeZoneOffset =  TTimeIntervalMinutes( 0 );
       
   513 	iTimeAttributes->iUtcDateTime = invalidTime.DateTime();
   511 	// Get all the information related to the plugin.
   514 	// Get all the information related to the plugin.
   512 	// The UTC time.
   515 	// The UTC time.
   513 	TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EUTCTime, iTimeAttributes ) );	
   516 	TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EUTCTime, iTimeAttributes ) );	
   514 	// The default offset.
   517 	// The default offset.
   515 	TRAP_IGNORE( aPluginImpl.GetTimeInformationL( ETZOffset, iTimeAttributes ) );
   518 	TRAP_IGNORE( aPluginImpl.GetTimeInformationL( ETZOffset, iTimeAttributes ) );
   517 	TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EDSTOffset, iTimeAttributes ) );
   520 	TRAP_IGNORE( aPluginImpl.GetTimeInformationL( EDSTOffset, iTimeAttributes ) );
   518 	
   521 	
   519 	// Set a flag saying we have plugin data.
   522 	// Set a flag saying we have plugin data.
   520 	iPluginData = ETrue;
   523 	iPluginData = ETrue;
   521 	
   524 	
   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 )
   525 	if( iMccReceived )
   539 		{
   526 		{
   540 		__PRINTS( "We have already recieved the MCC" );
   527 		__PRINTS( "We have already recieved the MCC" );
   541 		
   528 		
   542 		// Try to resolve the timezone id with the data that we have recieved.
   529 		// Try to resolve the timezone id with the data that we have recieved.
   543 		TInt timezoneId;
   530 		TInt timezoneId;
   544 		TRAP_IGNORE( TInt errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, iMcc, timezoneId ) );
   531 		TInt errorVal = 0;
       
   532 		TRAP_IGNORE( errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, iMcc, timezoneId ) );
   545 		
   533 		
   546 		__PRINT( "CClkSrvImpl::NotifyTimeChangeL - timeZoneId: %d", timezoneId );
   534 		__PRINT( "CClkSrvImpl::NotifyTimeChangeL - timeZoneId: %d", timezoneId );
   547 		
   535 		
   548 		__PRINT( "NotifyTimeChangeL::timezoneId : %d", timezoneId);
   536 		__PRINT( "NotifyTimeChangeL::timezoneId : %d", timezoneId);
   549 		
   537 		
   562 			CleanupStack::PushL( currentCTzId );
   550 			CleanupStack::PushL( currentCTzId );
   563 
   551 
   564 			if( KInvalidTimeZoneId != timezoneId ) 
   552 			if( KInvalidTimeZoneId != timezoneId ) 
   565 				{
   553 				{
   566                 // A valid new zone was found successfully
   554                 // 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 );
   555 				CTzId* newTzId = CTzId::NewL( timezoneId );
   585 				CleanupStack::PushL( newTzId );
   556 				CleanupStack::PushL( newTzId );
   586 
   557 
   587 				__PRINT( "NotifyTimeChangeL::currentCTzId : %d", currentCTzId->TimeZoneNumericID() );
   558 				__PRINT( "NotifyTimeChangeL::currentCTzId : %d", currentCTzId->TimeZoneNumericID() );
   588 
   559 
   590 
   561 
   591 				if( *newTzId != *currentCTzId )
   562 				if( *newTzId != *currentCTzId )
   592 					{
   563 					{
   593 					// The new zone is different than the current one
   564 					// The new zone is different than the current one
   594 					// GOAL 3: Set the DST zone of the device
   565 					// GOAL 3: Set the DST zone of the device
   595 					//if( staleBoot )
   566 					__PRINTS( "Timezone ID is different. Setting the zone." );
   596 					//{
       
   597 						__PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." );
       
   598 						
   567 						
   599 						TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) );
   568 					TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) );
   600 					//	}
       
   601 					}
   569 					}
   602 
   570 
   603 				CleanupStack::PopAndDestroy( newTzId );
   571 				CleanupStack::PopAndDestroy( newTzId );
   604 				}
   572 				}
   605 			
   573 			
   610 			TTime nwUtcTime( iTimeAttributes->iUtcDateTime );
   578 			TTime nwUtcTime( iTimeAttributes->iUtcDateTime );
   611 
   579 
   612 			// Set the UTC time only. This is being done because with the UTC time,
   580 			// 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.
   581 			// 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.
   582 			// If its not the first boot, then set the time.
   615 			//if( staleBoot )
   583 			__PRINTS( "Setting the UTC time." );
   616 			//	{
       
   617 				__PRINTS( "Not the first boot. Setting the UTC time." );
       
   618 				
   584 				
   619 				TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) );
   585 			TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) );
   620 			//	}
       
   621 			}
   586 			}
   622 		
   587 		
   623 		// Reset the flags.
   588 		// Reset the flags.
   624 		iPluginData = EFalse;
   589 		iPluginData = EFalse;
   625 		}
   590 		}
   631 		// 1. Use the plugin data and set the time.
   596 		// 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.
   597 		// 2. Use the offset in the plugindata or any available to deduce the timezone id.
   633 		
   598 		
   634 		// Try to resolve the timezone id with the data that we have recieved.
   599 		// Try to resolve the timezone id with the data that we have recieved.
   635 		TInt timezoneId;
   600 		TInt timezoneId;
       
   601 		TInt errorVal = 0;
   636 		const TBuf< 4 > invalidMCC( KInvalidMCC );
   602 		const TBuf< 4 > invalidMCC( KInvalidMCC );
   637 		TRAP_IGNORE( TInt errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, invalidMCC, timezoneId ) );
   603 		TRAP_IGNORE( errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, invalidMCC, timezoneId ) );
   638 		
   604 		
   639 		if( KErrNone == errorVal )
   605 		if( KErrNone == errorVal )
   640 			{
   606 			{
   641 			RTz tz;
   607 			RTz tz;
   642 			User::LeaveIfError( tz.Connect() );
   608 			User::LeaveIfError( tz.Connect() );
   647 			CleanupStack::PushL( currentCTzId );
   613 			CleanupStack::PushL( currentCTzId );
   648 			
   614 			
   649 			if( KInvalidTimeZoneId != timezoneId ) 
   615 			if( KInvalidTimeZoneId != timezoneId ) 
   650 				{
   616 				{
   651                 // A valid new zone was found successfully
   617                 // 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 );
   618 				CTzId* newTzId = CTzId::NewL( timezoneId );
   670 				CleanupStack::PushL( newTzId );
   619 				CleanupStack::PushL( newTzId );
   671 
   620 
   672 				if( *newTzId != *currentCTzId )
   621 				if( *newTzId != *currentCTzId )
   673 					{
   622 					{
   674 					// The new zone is different than the current one
   623 					// The new zone is different than the current one
   675 					// GOAL 3: Set the DST zone of the device
   624 					// GOAL 3: Set the DST zone of the device
   676 					// If firstboot then don't set the time.
   625 					// If firstboot then don't set the time.
   677 					//if( staleBoot )
   626 					__PRINTS( "The timezone ID is different. Setting the zone." );
   678 					//	{
       
   679 						__PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." );
       
   680 						
   627 						
   681 						TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) );
   628 					TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) );
   682 					//	}
       
   683 					}
   629 					}
   684 				CleanupStack::PopAndDestroy( newTzId );
   630 				CleanupStack::PopAndDestroy( newTzId );
   685 				}
   631 				}
   686 			CleanupStack::PopAndDestroy( currentCTzId );
   632 			CleanupStack::PopAndDestroy( currentCTzId );
   687 			CleanupStack::PopAndDestroy( &tz );
   633 			CleanupStack::PopAndDestroy( &tz );
   691 			TTime nwUtcTime( iTimeAttributes->iUtcDateTime );
   637 			TTime nwUtcTime( iTimeAttributes->iUtcDateTime );
   692 
   638 
   693 			// Set the UTC time only. This is being done because with the UTC time,
   639 			// 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.
   640 			// 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.
   641 			// Set the time only if its not the first boot.
   696 			//if( staleBoot )
   642 			__PRINTS( "Setting the UTC time." );
   697 			//    {
   643 
   698 			    __PRINTS( "Not the first boot. Setting the UTC time." );
   644 			TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) );
   699 
       
   700 			    TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) );
       
   701 			//    }
       
   702 			}
   645 			}
   703 		}
   646 		}
   704 	__PRINTS( "Notifying the timechange to client" );
   647 	__PRINTS( "Notifying the timechange to client" );
   705 	
   648 	
   706 	// Notify the sessions about the change.
   649 	// Notify the sessions about the change.
   731 		
   674 		
   732 		// We have atleast one protocol active.
   675 		// We have atleast one protocol active.
   733 		// Lets see if we can narrow down to a single timezone with the MCC recieved.
   676 		// Lets see if we can narrow down to a single timezone with the MCC recieved.
   734 		RArray< CTzId > tzIdArray;
   677 		RArray< CTzId > tzIdArray;
   735 		
   678 		
   736 		// Try and fetch the timezone ID using the MCC recieved.
   679 		// This parte of code introduced due to error ID EASH-82DPPC(3G Tests for NITZ and GPRS Interaction)
   737 		TRAP_IGNORE( iTzResolver->TzIdFromMccL( iMcc, tzIdArray, KInvalidTimeZoneId ) );
   680 		// Fix is bascially to narrowing down to single timezone id if NITZ packet is received prior to MCC.
   738 		
   681 		// In first IF state we are trying to narrowdown to single timezone ID, if not possible try to use MCC to get timezone
   739 		// Code to check if its the first boot.
   682 		// In second IF , we are using MCC to narrow down to single timezone ID directly as dont have NITZ info.
   740 		// Get the first boot status from cenrep. If it is the first boot, clockserver will not update the time.
   683 		if( iTimeAttributes )
   741 		TBool staleBoot( EFalse );
   684 		{
   742 		
   685             __PRINTS("timeatrrtibutes has value");
   743 		CRepository* cenRep( NULL );
   686 		
   744 
   687 			TTime invalidTime(0);
   745 		TRAPD( errorVal, cenRep = CRepository::NewL( KCRUidStartup ) );
   688 			if( iTimeAttributes->iDstOffset != TTimeIntervalMinutes( 0 ) &&
   746 		
   689 			iTimeAttributes->iTimeZoneOffset != TTimeIntervalMinutes( 0 ) &&
   747 		if( errorVal == KErrNone )
   690 			iTimeAttributes->iUtcDateTime.Year() != invalidTime.DateTime().Year() )
   748 			{
   691 			{
   749 			errorVal = cenRep->Get( KStartupFirstBoot, staleBoot );
   692 				// Try to resolve the timezone id with the data that we have recieved.
       
   693 				TInt timezoneId;
       
   694 				TRAP_IGNORE( TInt errorVal = iTzResolver->GetTimeZoneL( *iTimeAttributes, iMcc, timezoneId ) );
       
   695 				
       
   696 				__PRINT("TIMEZONE ID %d", timezoneId );
       
   697 
       
   698 				// Append the timezone id to array.
       
   699 
       
   700 				CTzId* matchingDSTZoneId = CTzId::NewL( timezoneId );
       
   701 				CleanupStack::PushL( matchingDSTZoneId );
       
   702 
       
   703 				tzIdArray.AppendL( *matchingDSTZoneId );
       
   704 
       
   705 				CleanupStack::PopAndDestroy( matchingDSTZoneId );
       
   706 
       
   707 				matchingDSTZoneId = NULL;
   750 			}
   708 			}
   751 		
   709 			else
   752 		// Cleanup
   710 			{
   753 		delete cenRep;
   711 				__PRINTS("NOT ABLE TO NARROW DOWN TO TIMEZONE ID WITH RECEIVED NITZ HENCE TRY WITH MCC");
   754 		cenRep = NULL;
   712 				// Not able to narrow down to single timezone id with received NITZ packet hence try with MCC.
   755 	
   713 				TRAP_IGNORE( iTzResolver->TzIdFromMccL( iMcc, tzIdArray, KInvalidTimeZoneId ) );	
       
   714 			}
       
   715 		}
       
   716 		else
       
   717 		{
       
   718 			__PRINTS("NO NITZ INFO HENCE TRY WITH MCC");
       
   719 			// No NITZ info hecne try with MCC to get the time zone Id.
       
   720 			TRAP_IGNORE( iTzResolver->TzIdFromMccL( iMcc, tzIdArray, KInvalidTimeZoneId ) );
       
   721 		}
       
   722 		
   756 		// A single matching timezone was found. Set it as the default one.
   723 		// A single matching timezone was found. Set it as the default one.
   757 		if( KSingleZone == tzIdArray.Count() )
   724 		if( KSingleZone == tzIdArray.Count() )
   758 			{
   725 			{
   759 			RTz tz;
   726 			RTz tz;
   760 			User::LeaveIfError( tz.Connect() );
   727 			User::LeaveIfError( tz.Connect() );
   778 				if( *newTzId != *currentCTzId ) 
   745 				if( *newTzId != *currentCTzId ) 
   779 					{
   746 					{
   780 					// The new zone is different than the current one
   747 					// The new zone is different than the current one
   781 					// Set the DST zone of the device
   748 					// Set the DST zone of the device
   782 					// Set the zone only for subsequent boots.
   749 					// Set the zone only for subsequent boots.
   783 					if( staleBoot )
   750 					__PRINTS( "The timezone ID is different. Setting the zone." );
   784 						{
       
   785 						__PRINTS( "Not the first boot and the timezone ID is different. Setting the zone." );
       
   786 						
   751 						
   787 						TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) );
   752 					TRAP_IGNORE( tz.SetTimeZoneL( *newTzId ) );
   788 						}
       
   789 					}
   753 					}
   790 				CleanupStack::PopAndDestroy( newTzId );
   754 				CleanupStack::PopAndDestroy( newTzId );
   791 				}
   755 				}
   792 			CleanupStack::PopAndDestroy( currentCTzId );
   756 			CleanupStack::PopAndDestroy( currentCTzId );
   793 			CleanupStack::PopAndDestroy( &tz );
   757 			CleanupStack::PopAndDestroy( &tz );		
   794 			}
   758 	
       
   759 		}
       
   760 		
       
   761 		// Set the time on device and set the attributes to null so that we avoid setting old value.		
       
   762 		if( iTimeAttributes )
       
   763 		    {
       
   764             // Time sent by nw is UTC
       
   765             TTime nwUtcTime( iTimeAttributes->iUtcDateTime);
       
   766     
       
   767             // Set the UTC time only. This is being done because with the UTC time,
       
   768             // before the time is being set, the dst properties for the timezone are being checked.
       
   769             // If its not the first boot, then set the time.
       
   770             __PRINTS( "Setting the UTC time." );
       
   771     
       
   772             TRAP_IGNORE( User::SetUTCTime( nwUtcTime ) );
       
   773     
       
   774             // Setting the attributes to null again as we dont trust on
       
   775             // previous NITZ data recevied by device.If device receive
       
   776             // NITZ data again attributes would get filled with actual value.
       
   777             // Has been kept outside because this statement is valid for
       
   778             // first boot also.
       
   779     
       
   780             iTimeAttributes->iDstOffset = TTimeIntervalMinutes( 0 );
       
   781             iTimeAttributes->iTimeZoneOffset =  TTimeIntervalMinutes( 0 );
       
   782             TTime invalidTime( 0 );
       
   783             iTimeAttributes->iUtcDateTime = invalidTime.DateTime(); 
       
   784             }
   795 		}
   785 		}
   796 	
   786 	
   797 	// Notify the sessions about the change in mcc.
   787 	// Notify the sessions about the change in mcc.
   798 	iClkSrv->NotifyAboutChange( EComponentMcc, 0, KErrNone );
   788 	iClkSrv->NotifyAboutChange( EComponentMcc, 0, KErrNone );
   799 	
   789