48 |
48 |
49 // --------------------------------------------------------- |
49 // --------------------------------------------------------- |
50 // CDRMNitzObserver::CDRMNitzObserver |
50 // CDRMNitzObserver::CDRMNitzObserver |
51 // Default Constructor |
51 // Default Constructor |
52 // --------------------------------------------------------- |
52 // --------------------------------------------------------- |
53 // |
53 // |
54 CDRMNitzObserver::CDRMNitzObserver( RMobilePhone& aMobilePhone, CDRMClock* aDRMClock) : |
54 CDRMNitzObserver::CDRMNitzObserver( RMobilePhone& aMobilePhone, CDRMClock* aDRMClock) : |
55 CActive(EPriorityNormal) ,iDRMClock( aDRMClock ), iMobilePhone( &aMobilePhone ), |
55 CActive(EPriorityNormal) ,iDRMClock( aDRMClock ), iMobilePhone( &aMobilePhone ), |
56 iError( KErrNone ) |
56 iError( KErrNone ) |
57 { |
57 { |
58 } |
58 } |
59 |
59 |
60 // --------------------------------------------------------- |
60 // --------------------------------------------------------- |
61 // CDRMNitzObserver::~CDRMNitzObserver |
61 // CDRMNitzObserver::~CDRMNitzObserver |
62 // Destructor |
62 // Destructor |
63 // --------------------------------------------------------- |
63 // --------------------------------------------------------- |
64 // |
64 // |
65 CDRMNitzObserver::~CDRMNitzObserver() |
65 CDRMNitzObserver::~CDRMNitzObserver() |
66 { |
66 { |
67 Cancel(); |
67 Cancel(); |
68 }; |
68 }; |
69 |
69 |
70 |
70 |
71 // --------------------------------------------------------- |
71 // --------------------------------------------------------- |
72 // CDRMNitzObserver::ConstructL |
72 // CDRMNitzObserver::ConstructL |
73 // Two-phase Constructor |
73 // Two-phase Constructor |
74 // --------------------------------------------------------- |
74 // --------------------------------------------------------- |
75 // |
75 // |
76 void CDRMNitzObserver::ConstructL() |
76 void CDRMNitzObserver::ConstructL() |
77 { |
77 { |
78 DRMLOG( _L("ConstructL ")); |
78 DRMLOG( _L("ConstructL ")); |
79 |
79 |
80 // Get the NITZ info on the creation, might not be available yet |
80 // Get the NITZ info on the creation, might not be available yet |
81 iError = iMobilePhone->GetNITZInfo(iNitzInfo); |
81 iError = iMobilePhone->GetNITZInfo(iNitzInfo); |
82 |
82 |
83 |
83 |
84 DRMLOG2( _L("ConstructL: Error = %d"), iError ); |
84 DRMLOG2( _L("ConstructL: Error = %d"), iError ); |
85 |
85 |
86 } |
86 } |
87 |
87 |
88 |
88 |
89 // --------------------------------------------------------- |
89 // --------------------------------------------------------- |
90 // CDRMNitzObserver::NewL |
90 // CDRMNitzObserver::NewL |
91 // Two-phase constructor |
91 // Two-phase constructor |
92 // --------------------------------------------------------- |
92 // --------------------------------------------------------- |
93 // |
93 // |
94 CDRMNitzObserver* CDRMNitzObserver::NewL( RMobilePhone& aMobilePhone, |
94 CDRMNitzObserver* CDRMNitzObserver::NewL( RMobilePhone& aMobilePhone, |
95 CDRMClock* aDRMClock) |
95 CDRMClock* aDRMClock) |
96 { |
96 { |
97 CDRMNitzObserver* self = new(ELeave) CDRMNitzObserver(aMobilePhone,aDRMClock); |
97 CDRMNitzObserver* self = new(ELeave) CDRMNitzObserver(aMobilePhone,aDRMClock); |
98 CleanupStack::PushL(self); |
98 CleanupStack::PushL(self); |
99 self->ConstructL(); |
99 self->ConstructL(); |
100 CleanupStack::Pop(); |
100 CleanupStack::Pop(); |
101 return self; |
101 return self; |
102 } |
102 } |
103 |
103 |
104 // --------------------------------------------------------- |
104 // --------------------------------------------------------- |
105 // CDRMNitzObserver::Start |
105 // CDRMNitzObserver::Start |
106 // Adds the active object into the ActiveScheduler |
106 // Adds the active object into the ActiveScheduler |
107 // and sets the object active, makes sure RunL is called |
107 // and sets the object active, makes sure RunL is called |
108 // atleast once |
108 // atleast once |
109 // --------------------------------------------------------- |
109 // --------------------------------------------------------- |
110 // |
110 // |
111 void CDRMNitzObserver::Start() |
111 void CDRMNitzObserver::Start() |
112 { |
112 { |
113 TRequestStatus* status = 0; |
113 TRequestStatus* status = 0; |
114 |
114 |
115 DRMLOG2( _L("iError == %d "), iError ); |
115 DRMLOG2( _L("iError == %d "), iError ); |
116 |
116 |
117 if( iError == KErrNotSupported ) |
117 if( iError == KErrNotSupported ) |
118 { |
118 { |
119 // NITZ never supported, kill the observer |
119 // NITZ never supported, kill the observer |
120 if( IsAdded() ) |
120 if( IsAdded() ) |
121 { |
121 { |
122 Deque(); |
122 Deque(); |
123 return; |
123 return; |
124 } |
124 } |
125 return; |
125 return; |
126 } |
126 } |
127 |
127 |
128 if( !IsAdded() ) |
128 if( !IsAdded() ) |
129 { |
129 { |
130 CActiveScheduler::Add(this); |
130 CActiveScheduler::Add(this); |
131 } |
131 } |
132 if ( !IsActive() ) |
132 if ( !IsActive() ) |
133 { |
133 { |
134 SetActive(); |
134 SetActive(); |
135 } |
135 } |
136 status = &iStatus; |
136 status = &iStatus; |
137 User::RequestComplete(status,KErrNone); |
137 User::RequestComplete(status,KErrNone); |
138 } |
138 } |
139 |
139 |
140 |
140 |
141 // Ignore the error: |
141 // Ignore the error: |
142 TInt CDRMNitzObserver::RunError( TInt /*aError*/ ) |
142 TInt CDRMNitzObserver::RunError( TInt /*aError*/ ) |
143 { |
143 { |
144 SetActive(); |
144 SetActive(); |
145 return KErrNone; |
145 return KErrNone; |
146 } |
146 } |
147 |
147 |
148 |
148 |
149 // --------------------------------------------------------- |
149 // --------------------------------------------------------- |
150 // CDRMNitzObserver::RunL |
150 // CDRMNitzObserver::RunL |
151 // Active object RunL |
151 // Active object RunL |
152 // --------------------------------------------------------- |
152 // --------------------------------------------------------- |
153 // |
153 // |
154 void CDRMNitzObserver::RunL() |
154 void CDRMNitzObserver::RunL() |
155 { |
155 { |
156 TTime timeData; |
156 TTime timeData; |
157 TInt timeZone( 0 ); |
157 TInt timeZone( 0 ); |
158 |
158 |
159 // Check if the nitz has changed and is available, if so call update |
159 // Check if the nitz has changed and is available, if so call update |
160 // otherwise just wait |
160 // otherwise just wait |
161 |
161 |
162 DRMLOG( _L("ObserverRunL Called\n\r ") ); |
162 DRMLOG( _L("ObserverRunL Called\n\r ") ); |
163 |
163 |
164 iStatus = KRequestPending; |
164 iStatus = KRequestPending; |
165 |
165 |
166 iMobilePhone->NotifyNITZInfoChange(iStatus, iNitzInfo); |
166 iMobilePhone->NotifyNITZInfoChange(iStatus, iNitzInfo); |
167 |
167 |
168 DRMLOG( _L("NotifyNITZInfoChange:")); |
168 DRMLOG( _L("NotifyNITZInfoChange:")); |
169 if( GetNitzTime( timeData, timeZone ) ) |
169 if( GetNitzTime( timeData, timeZone ) ) |
170 { |
170 { |
171 DRMLOG( _L("Resetting secure time from NITZ observer:")); |
171 DRMLOG( _L("Resetting secure time from NITZ observer:")); |
172 TRAPD(error, iDRMClock->ResetSecureTimeL( timeData, timeZone ) ); |
172 TRAPD(error, iDRMClock->ResetSecureTimeL( timeData, timeZone ) ); |
173 if( error ) |
173 if( error ) |
174 { |
174 { |
175 DRMLOG( _L("Resetting secure time from NITZ observer returned an error.")); |
175 DRMLOG( _L("Resetting secure time from NITZ observer returned an error.")); |
176 } |
176 } |
177 DRMLOG( _L("Resetting secure time from NITZ observer successful.")); |
177 DRMLOG( _L("Resetting secure time from NITZ observer successful.")); |
178 |
178 |
179 if( error != KErrArgument ) |
179 if( error != KErrArgument ) |
180 { |
180 { |
181 if( error ) |
181 if( error ) |
182 { |
182 { |
183 DRMLOG( _L("ObserverRunL Called error \n\r ") ); |
183 DRMLOG( _L("ObserverRunL Called error \n\r ") ); |
184 } |
184 } |
185 User::LeaveIfError( error ); |
185 User::LeaveIfError( error ); |
186 } |
186 } |
187 } |
187 } |
188 |
188 |
225 // --------------------------------------------------------- |
225 // --------------------------------------------------------- |
226 // |
226 // |
227 TBool CDRMNitzObserver::GetNitzTime(TTime& aNitzTime, TInt& aTimeZone) |
227 TBool CDRMNitzObserver::GetNitzTime(TTime& aNitzTime, TInt& aTimeZone) |
228 { |
228 { |
229 TInt32 nitzCaps(iNitzInfo.iNitzFieldsUsed); |
229 TInt32 nitzCaps(iNitzInfo.iNitzFieldsUsed); |
230 |
230 |
231 if (nitzCaps & RMobilePhone::KCapsTimezoneAvailable) |
231 if (nitzCaps & RMobilePhone::KCapsTimezoneAvailable) |
232 { |
232 { |
233 TInt timezone(iNitzInfo.iTimeZone & KTimeZoneValidBit); |
233 TInt timezone(iNitzInfo.iTimeZone & KTimeZoneValidBit); |
234 |
234 |
235 if (iNitzInfo.iTimeZone & KTimeZoneSignBit) |
235 if (iNitzInfo.iTimeZone & KTimeZoneSignBit) |
236 { |
236 { |
237 // Changes sign |
237 // Changes sign |
238 timezone = - timezone; |
238 timezone = - timezone; |
239 } |
239 } |
240 |
240 |
241 // TimeZone info |
241 // TimeZone info |
242 aTimeZone = timezone; |
242 aTimeZone = timezone; |
243 } |
243 } |
244 |
244 |
245 if (nitzCaps & RMobilePhone::KCapsTimeAvailable) |
245 if (nitzCaps & RMobilePhone::KCapsTimeAvailable) |
246 { |
246 { |
247 TDateTime dateTime; |
247 TDateTime dateTime; |
248 TInt fourDigitYear(iNitzInfo.Year()); |
248 TInt fourDigitYear(iNitzInfo.Year()); |
249 |
249 |
250 //Check if our TSY returns 2 digits in stead of 4 digits for the year value |
250 //Check if our TSY returns 2 digits in stead of 4 digits for the year value |
251 if (fourDigitYear <= KMaximumTwoDigitValue) // The maximum year value in UI applications is 2060 |
251 if (fourDigitYear <= KMaximumTwoDigitValue) // The maximum year value in UI applications is 2060 |
252 { |
252 { |
253 //The year received from TSY is 2 digits we make it 4 digits |
253 //The year received from TSY is 2 digits we make it 4 digits |
254 fourDigitYear = fourDigitYear + KNitzYearOffset; // 2000 |
254 fourDigitYear = fourDigitYear + KNitzYearOffset; // 2000 |
255 } |
255 } |
256 |
256 |
257 dateTime.Set(fourDigitYear, |
257 dateTime.Set(fourDigitYear, |
258 TMonth(iNitzInfo.Month()), |
258 TMonth(iNitzInfo.Month()), |
259 iNitzInfo.Day(), |
259 iNitzInfo.Day(), |
260 iNitzInfo.Hour(), |
260 iNitzInfo.Hour(), |
261 iNitzInfo.Minute(), |
261 iNitzInfo.Minute(), |
262 iNitzInfo.Second(), |
262 iNitzInfo.Second(), |
263 iNitzInfo.MicroSecond()); |
263 iNitzInfo.MicroSecond()); |
264 |
264 |
265 DRMLOG2( _L( "CDRMNitzObserver::GetNitzTime: DateTime: %d" ), fourDigitYear ); |
265 DRMLOG2( _L( "CDRMNitzObserver::GetNitzTime: DateTime: %d" ), fourDigitYear ); |
266 DRMLOG2( _L( ":%d" ), iNitzInfo.Month() ); |
266 DRMLOG2( _L( ":%d" ), iNitzInfo.Month() ); |
267 DRMLOG2( _L( ":%d" ), iNitzInfo.Day() ); |
267 DRMLOG2( _L( ":%d" ), iNitzInfo.Day() ); |
268 DRMLOG2( _L( ":%d" ), iNitzInfo.Hour() ); |
268 DRMLOG2( _L( ":%d" ), iNitzInfo.Hour() ); |