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