|
1 /* |
|
2 * Copyright (c) 2004,2006 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: Implements the CAOSettings class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <centralrepository.h> |
|
21 |
|
22 #include "caosettings.h" |
|
23 #include "logger.h" |
|
24 #include "maosettingsobserver.h" |
|
25 #include "pdpcontextmanagerinternalcrkeys.h" |
|
26 |
|
27 // UNNAMED NAMESPACE FOR LOCAL DEFINITIONS |
|
28 namespace |
|
29 { |
|
30 // CONSTANTS |
|
31 #ifdef _DEBUG |
|
32 _LIT( KPanicCat, "Settings" ); |
|
33 #endif |
|
34 |
|
35 // Default values |
|
36 const TInt KDefaultRetryInterval = 1; |
|
37 const TInt KDefaultIAPUid = 1; |
|
38 const TInt KDefaultConnectionInterval = 25; |
|
39 const TInt KDefaultUnconnectInterval = 25; |
|
40 const TInt KLingerOff = 0; |
|
41 const TInt KLingerForEver = -1; |
|
42 |
|
43 const TUint KIapColumn = 0x00000100; |
|
44 const TUint KLingerColumn = 0x00000200; |
|
45 |
|
46 // DATA TYPES |
|
47 enum TPanicCode |
|
48 { |
|
49 EAlreadyFetchingSettings, |
|
50 ENotActive |
|
51 }; |
|
52 |
|
53 // LOCAL FUNCTIONS |
|
54 #ifdef _DEBUG |
|
55 LOCAL_C void Panic( TPanicCode aCode ) |
|
56 { |
|
57 User::Panic( KPanicCat, aCode ); |
|
58 } |
|
59 #endif |
|
60 } |
|
61 |
|
62 // METHODS |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CAOSettings::NewL |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CAOSettings* CAOSettings::NewL( MAOSettingsObserver& aObserver ) |
|
69 { |
|
70 LOG_1( _L("CAOSettings::NewL") ); |
|
71 |
|
72 CAOSettings* self = new( ELeave ) CAOSettings( aObserver ); |
|
73 |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop( self ); |
|
77 |
|
78 return self; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CAOSettings::~CAOSettings |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CAOSettings::~CAOSettings() |
|
86 { |
|
87 LOG_1( _L("CAOSettings::~CAOSettings") ); |
|
88 |
|
89 Cancel(); |
|
90 if ( iCenRepNotifyHandler ) |
|
91 { |
|
92 iCenRepNotifyHandler->StopListening(); |
|
93 delete iCenRepNotifyHandler; |
|
94 } |
|
95 delete iRepository; |
|
96 |
|
97 iLingerSettings.Close(); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CAOSettings::CAOSettings |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CAOSettings::CAOSettings( MAOSettingsObserver& aObserver ): |
|
105 CActive( CActive::EPriorityStandard ), |
|
106 iObserver( aObserver ), |
|
107 iIAP( KDefaultIAPUid ), |
|
108 iRetryTimerValue( KDefaultRetryInterval ), |
|
109 iSupportedInHPLMN( EFalse ), |
|
110 iSupportedInVPLMN( EFalse ), |
|
111 iLingerTimerValue( KLingerOff ) |
|
112 { |
|
113 LOG_1( _L("CAOSettings::CAOSettings") ); |
|
114 |
|
115 CActiveScheduler::Add( this ); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CAOSettings::ConstructL |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CAOSettings::ConstructL() |
|
123 { |
|
124 LOG_1( _L("CAOSettings::ConstructL") ); |
|
125 |
|
126 // Create cenrep |
|
127 iRepository = CRepository::NewL( KCRUidPDPContextManager ); |
|
128 |
|
129 // Create cenrep listener |
|
130 iCenRepNotifyHandler = CCenRepNotifyHandler::NewL( |
|
131 *this, |
|
132 *iRepository ); |
|
133 iCenRepNotifyHandler->StartListeningL(); |
|
134 |
|
135 // Get connection timer value |
|
136 iConnectionTimerValue = KDefaultConnectionInterval; |
|
137 UpdateConnectionTimerSetting(); |
|
138 |
|
139 // Get unconnect timer value |
|
140 iUnconnectTimerValue = KDefaultUnconnectInterval; |
|
141 UpdateUnconnectTimerSetting(); |
|
142 |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CAOSettings::FetchSettings |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CAOSettings::FetchSettings( TUint32 aId ) |
|
150 { |
|
151 LOG_2( _L("CAOSettings::FetchSettings: aId: %d"), aId ); |
|
152 |
|
153 __ASSERT_DEBUG( !IsActive(), Panic( EAlreadyFetchingSettings ) ); |
|
154 |
|
155 // Let just scheduler run and get settings when RunL is called |
|
156 iSettingsToFetch = aId; |
|
157 iStatus = KRequestPending; |
|
158 SetActive(); |
|
159 CompleteSelf( iStatus, KErrNone ); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CAOSettings::RunL |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CAOSettings::RunL() |
|
167 { |
|
168 LOG_2( _L("CAOSettings::RunL: iStatus: %d"), iStatus.Int() ); |
|
169 |
|
170 // Currently we cannot complete with an error |
|
171 SetupSettings( iSettingsToFetch ); |
|
172 iObserver.HandleSettingsChangedL(); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CAOSettings::DoCancel |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 void CAOSettings::DoCancel() |
|
180 { |
|
181 LOG_1( _L("CAOSettings::DoCancel") ); |
|
182 |
|
183 // We must complete pending request if needed |
|
184 // Checking IsActive is not sufficient, we must check also |
|
185 // iStatus |
|
186 if ( iStatus == KRequestPending && IsActive() ) |
|
187 { |
|
188 CompleteSelf( iStatus, KErrCancel ); |
|
189 } |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CAOSettings::RunError |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 TInt CAOSettings::RunError( TInt /*aError*/ ) |
|
197 { |
|
198 LOG_1( _L("CAOSettings::RunError") ); |
|
199 return KErrNone; |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CAOSettings::AccessPointId |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 TInt CAOSettings::AccessPointId() const |
|
207 { |
|
208 LOG_1( _L("CAOSettings::AccessPointId") ); |
|
209 |
|
210 return iIAP; |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CAOSettings::RetryTimerValue |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CAOSettings::RetryTimerValue() const |
|
218 { |
|
219 LOG_1( _L("CAOSettings::RetryTimerValue") ); |
|
220 |
|
221 return iRetryTimerValue; |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CAOSettings::AlwaysOnSupportedInHPLMN |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 TBool CAOSettings::AlwaysOnSupportedInHPLMN() const |
|
229 { |
|
230 LOG_1( _L("CAOSettings::AlwaysOnSupportedInHPLMN") ); |
|
231 |
|
232 return iSupportedInHPLMN; |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // CAOSettings::AlwaysOnSupportedInVPLMN |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 TBool CAOSettings::AlwaysOnSupportedInVPLMN() const |
|
240 { |
|
241 LOG_1( _L("CAOSettings::AlwaysOnSupportedInVPLMN") ); |
|
242 |
|
243 return iSupportedInVPLMN; |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CAOSettings::ConnectionTimerValue |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 TInt CAOSettings::ConnectionTimerValue() const |
|
251 { |
|
252 LOG_1( _L("CAOSettings::ConnectionTimerValue") ); |
|
253 |
|
254 return iConnectionTimerValue; |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CAOSettings::UnconnectTimerValue |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CAOSettings::UnconnectTimerValue() const |
|
262 { |
|
263 LOG_1( _L("CAOSettings::UnconnectTimerValue") ); |
|
264 |
|
265 return iUnconnectTimerValue; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CAOSettings::LingerTimerValue |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 TInt CAOSettings::LingerTimerValue( const TUint aIapId ) const |
|
273 { |
|
274 LOG_1( _L("CAOSettings::LingerTimerValue") ); |
|
275 |
|
276 for ( TInt j=0; j < iLingerSettings.Count(); j++ ) |
|
277 { |
|
278 if ( iLingerSettings[ j ].iIap == aIapId ) |
|
279 { |
|
280 LOG_3( _L("Linger setting found >> iap: %d, interval: %d"), |
|
281 aIapId, |
|
282 iLingerSettings[ j ].iInterval); |
|
283 |
|
284 if ( iLingerSettings[ j ].iInterval == 0 ) |
|
285 { |
|
286 return KLingerForEver; |
|
287 } |
|
288 else |
|
289 { |
|
290 return ( iLingerSettings[ j ].iInterval ); |
|
291 } |
|
292 } |
|
293 } |
|
294 |
|
295 LOG_2( _L("LingerTimerValue() not found >> iap: %d"), |
|
296 aIapId ); |
|
297 |
|
298 return KLingerOff; // Linger is off |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CAOSettings::HandleNotifyGeneric |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 void CAOSettings::HandleNotifyGeneric( TUint32 aId ) |
|
306 { |
|
307 LOG_2( _L("CAOSettings::HandleNotifyGeneric: aId: %d"), aId ); |
|
308 |
|
309 switch ( aId ) |
|
310 { |
|
311 // We are interested only in Always-On settings |
|
312 case KPDPContextManagerDefaultUid: |
|
313 case KPDPContextManagerRetryTimer: |
|
314 case KPDPContextManagerConnectionTimer: |
|
315 case KPDPContextManagerUnconnectTimer: |
|
316 case KPDPContextManagerEnableWhenRoaming: |
|
317 case KPDPContextManagerEnableWhenHome: |
|
318 { |
|
319 FetchSettings( aId ); |
|
320 break; |
|
321 } |
|
322 default: |
|
323 { |
|
324 if ( ( aId & KLingerColumn ) == KLingerColumn ) |
|
325 { |
|
326 FetchSettings( KPDPContextManagerLinger ); |
|
327 } |
|
328 |
|
329 break; |
|
330 } |
|
331 } |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // CAOSettings::SetupSettings |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 void CAOSettings::SetupSettings( TUint32 aId ) |
|
339 { |
|
340 LOG_2( _L("CAOSettings::SetupSettings: aId: %d"), aId ); |
|
341 |
|
342 switch ( aId ) |
|
343 { |
|
344 case KPDPContextManagerDefaultUid: |
|
345 { |
|
346 UpdateIAPSetting(); |
|
347 break; |
|
348 } |
|
349 case KPDPContextManagerRetryTimer: |
|
350 { |
|
351 UpdateRetryTimerSetting(); |
|
352 break; |
|
353 } |
|
354 case KPDPContextManagerConnectionTimer: |
|
355 { |
|
356 UpdateConnectionTimerSetting(); |
|
357 break; |
|
358 } |
|
359 case KPDPContextManagerUnconnectTimer: |
|
360 { |
|
361 UpdateUnconnectTimerSetting(); |
|
362 break; |
|
363 } |
|
364 case KPDPContextManagerEnableWhenHome: |
|
365 { |
|
366 UpdateHPLMNSetting(); |
|
367 break; |
|
368 } |
|
369 case KPDPContextManagerEnableWhenRoaming: |
|
370 { |
|
371 UpdateVPLMNSetting(); |
|
372 break; |
|
373 } |
|
374 case KPDPContextManagerLinger: |
|
375 { |
|
376 UpdateLingerTimerSetting(); |
|
377 break; |
|
378 } |
|
379 default: |
|
380 { |
|
381 // Set all |
|
382 UpdateIAPSetting(); |
|
383 UpdateRetryTimerSetting(); |
|
384 UpdateConnectionTimerSetting(); |
|
385 UpdateUnconnectTimerSetting(); |
|
386 UpdateHPLMNSetting(); |
|
387 UpdateVPLMNSetting(); |
|
388 UpdateLingerTimerSetting(); |
|
389 break; |
|
390 } |
|
391 } |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // CAOSettings::CompleteSelf |
|
396 // --------------------------------------------------------------------------- |
|
397 // |
|
398 void CAOSettings::CompleteSelf( TRequestStatus& aStatus, TInt aReason ) |
|
399 { |
|
400 LOG_1( _L("CAOSettings::CompleteSelf") ); |
|
401 |
|
402 __ASSERT_DEBUG( IsActive(), Panic( ENotActive ) ); |
|
403 |
|
404 TRequestStatus* status = &aStatus; |
|
405 User::RequestComplete( status, aReason ); |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // CAOSettings::UpdateIAPSetting |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 void CAOSettings::UpdateIAPSetting() |
|
413 { |
|
414 LOG_2( _L("CAOSettings::UpdateIAPSettingL >> Old value: %d"), iIAP ); |
|
415 |
|
416 UpdateSetting( KPDPContextManagerDefaultUid, iIAP ); |
|
417 |
|
418 LOG_2( _L("CAOSettings::UpdateIAPSettingL >> New value: %d"), iIAP ); |
|
419 } |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // CAOSettings::UpdateRetryTimerSetting |
|
423 // --------------------------------------------------------------------------- |
|
424 // |
|
425 void CAOSettings::UpdateRetryTimerSetting() |
|
426 { |
|
427 LOG_2( _L("CAOSettings::UpdateRetryTimerSetting >> Old value: %d"), |
|
428 iRetryTimerValue ); |
|
429 |
|
430 UpdateSetting( KPDPContextManagerRetryTimer, iRetryTimerValue ); |
|
431 |
|
432 LOG_2( _L("CAOSettings::UpdateRetryTimerSetting >> New value: %d"), |
|
433 iRetryTimerValue ); |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // CAOSettings::UpdateConnectionTimerSetting |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 void CAOSettings::UpdateConnectionTimerSetting() |
|
441 { |
|
442 LOG_2( _L("CAOSettings::UpdateConnectionTimerSetting >> Old value: %d"), |
|
443 iConnectionTimerValue ); |
|
444 |
|
445 UpdateSetting( KPDPContextManagerConnectionTimer, iConnectionTimerValue ); |
|
446 |
|
447 LOG_2( _L("CAOSettings::UpdateConnectionTimerSetting >> New value: %d"), |
|
448 iConnectionTimerValue ); |
|
449 } |
|
450 |
|
451 // --------------------------------------------------------------------------- |
|
452 // CAOSettings::UpdateUnconnectTimerSetting |
|
453 // --------------------------------------------------------------------------- |
|
454 // |
|
455 void CAOSettings::UpdateUnconnectTimerSetting() |
|
456 { |
|
457 LOG_2( _L("CAOSettings::UpdateUnconnectTimerSetting >> Old value: %d"), |
|
458 iUnconnectTimerValue ); |
|
459 |
|
460 UpdateSetting( KPDPContextManagerUnconnectTimer, iUnconnectTimerValue ); |
|
461 |
|
462 LOG_2( _L("CAOSettings::UpdateUnconnectTimerSetting >> New value: %d"), |
|
463 iUnconnectTimerValue ); |
|
464 } |
|
465 |
|
466 |
|
467 // --------------------------------------------------------------------------- |
|
468 // CAOSettings::UpdateHPLMNSetting |
|
469 // --------------------------------------------------------------------------- |
|
470 // |
|
471 void CAOSettings::UpdateHPLMNSetting() |
|
472 { |
|
473 LOG_2( _L("CAOSettings::UpdateHPLMNSetting >> Old value: %d"), |
|
474 iSupportedInHPLMN ); |
|
475 |
|
476 UpdateSetting( KPDPContextManagerEnableWhenHome, iSupportedInHPLMN ); |
|
477 |
|
478 LOG_2( _L("CAOSettings::UpdateHPLMNSetting >> New value: %d"), |
|
479 iSupportedInHPLMN ); |
|
480 } |
|
481 |
|
482 // --------------------------------------------------------------------------- |
|
483 // CAOSettings::UpdateVPLMNSetting |
|
484 // --------------------------------------------------------------------------- |
|
485 // |
|
486 void CAOSettings::UpdateVPLMNSetting() |
|
487 { |
|
488 LOG_2( _L("CAOSettings::UpdateVPLMNSetting >> Old value: %d"), |
|
489 iSupportedInVPLMN ); |
|
490 |
|
491 UpdateSetting( KPDPContextManagerEnableWhenRoaming, iSupportedInVPLMN ); |
|
492 |
|
493 LOG_2( _L("CAOSettings::UpdateVPLMNSetting >> New value: %d"), |
|
494 iSupportedInVPLMN ); |
|
495 } |
|
496 |
|
497 // --------------------------------------------------------------------------- |
|
498 // CAOSettings::UpdateLingerTimerSetting |
|
499 // --------------------------------------------------------------------------- |
|
500 // |
|
501 void CAOSettings::UpdateLingerTimerSetting() |
|
502 { |
|
503 LOG_1( _L("CAOSettings::UpdateLingerTimerSetting")); |
|
504 |
|
505 TInt count( 0 ); |
|
506 TInt err( KErrNone ); |
|
507 TLingerSetting ls; |
|
508 |
|
509 iLingerSettings.Reset(); |
|
510 |
|
511 // Get number of entries (iapId&linger) in Centrep |
|
512 err = iRepository->Get( KPdpContextManagerLingerArrayCount, count ); |
|
513 |
|
514 if ( err == KErrNone ) |
|
515 { |
|
516 // read all entries from Centrep |
|
517 for ( TInt row=1; row <= count; row++ ) |
|
518 { |
|
519 err = iRepository->Get( ( KIapColumn | row ), ls.iIap ); |
|
520 |
|
521 if ( err == KErrNone ) |
|
522 { |
|
523 err = iRepository->Get( ( KLingerColumn | row ), ls.iInterval ); |
|
524 } |
|
525 |
|
526 if ( err == KErrNone ) |
|
527 { |
|
528 iLingerSettings.Append( ls ); |
|
529 } |
|
530 else |
|
531 { |
|
532 LOG_3( _L("CRepository::Get() failed >> err: %d, row: %d"), |
|
533 err, row); |
|
534 |
|
535 return; |
|
536 } |
|
537 } |
|
538 } |
|
539 else |
|
540 { |
|
541 LOG_2( _L("CRepository::Get( KPdpContextManagerLingerArrayCount) >> err: %d"), |
|
542 err); |
|
543 } |
|
544 |
|
545 // Write to log |
|
546 for ( TInt j=0; j < iLingerSettings.Count(); j++ ) |
|
547 { |
|
548 LOG_3( _L("iLingerSettings >> iap: %d, interval: %d"), |
|
549 iLingerSettings[ j ].iIap, |
|
550 iLingerSettings[ j ].iInterval); |
|
551 } |
|
552 } |
|
553 |
|
554 // --------------------------------------------------------------------------- |
|
555 // CAOSettings::UpdateSetting |
|
556 // --------------------------------------------------------------------------- |
|
557 // |
|
558 void CAOSettings::UpdateSetting( TUint32 aId, TInt& aValue ) |
|
559 { |
|
560 LOG_2( _L("CAOSettings::UpdateSetting: %d"), aId ); |
|
561 |
|
562 TInt value = 0; |
|
563 TInt err = iRepository->Get( aId, value ); |
|
564 if ( err == KErrNone ) |
|
565 { |
|
566 // New value got, store it |
|
567 aValue = value; |
|
568 } |
|
569 } |
|
570 |
|
571 // End of file |