17 // Version : 1.0 |
17 // Version : 1.0 |
18 // |
18 // |
19 #include <commsdattypesv1_1.h> |
19 #include <commsdattypesv1_1.h> |
20 #include <commdb.h> |
20 #include <commdb.h> |
21 #include <commsdat.h> |
21 #include <commsdat.h> |
|
22 #include <cmgenconnsettings.h> |
|
23 #include <cmmanagerkeys.h> |
22 #include "sipapnconfigurationhandler.h" |
24 #include "sipapnconfigurationhandler.h" |
23 #include "SipProfileLog.h" |
25 #include "SipProfileLog.h" |
24 |
26 |
25 // ----------------------------------------------------------------------------- |
27 // ----------------------------------------------------------------------------- |
26 // CSIPApnConfigurationHandler::NewL |
28 // CSIPApnConfigurationHandler::NewL |
283 TInt CSIPApnConfigurationHandler::RunError( TInt aError ) |
283 TInt CSIPApnConfigurationHandler::RunError( TInt aError ) |
284 { |
284 { |
285 PROFILE_DEBUG3( |
285 PROFILE_DEBUG3( |
286 "CSIPApnConfigurationHandler::RunError() err", aError ); |
286 "CSIPApnConfigurationHandler::RunError() err", aError ); |
287 |
287 |
|
288 if(iCellularDataBlocked) |
|
289 { |
|
290 AllowCellularDataUsage(); |
|
291 } |
|
292 |
288 if ( aError != KErrNoMemory && aError != KErrNone ) |
293 if ( aError != KErrNoMemory && aError != KErrNone ) |
289 { |
294 { |
290 iObserver.ApnChanged( *iApnProposal, iIapId, aError ); |
295 iObserver.ApnChanged( *iApnProposal, iIapId, aError ); |
291 aError = KErrNone; |
296 aError = KErrNone; |
292 } |
297 } |
305 iMonitoringState( EMonitoringIdle ) |
310 iMonitoringState( EMonitoringIdle ) |
306 { |
311 { |
307 CActiveScheduler::Add( this ); |
312 CActiveScheduler::Add( this ); |
308 iIapId = aIapId; |
313 iIapId = aIapId; |
309 iIsFailed = EFalse; |
314 iIsFailed = EFalse; |
310 iIsFatalFailure = EFalse; |
315 iIsFatalFailure = EFalse; |
|
316 iCellularDataBlocked = EFalse; |
311 } |
317 } |
312 |
318 |
313 // ----------------------------------------------------------------------------- |
319 // ----------------------------------------------------------------------------- |
314 // CSIPApnConfigurationHandler::ConstructL |
320 // CSIPApnConfigurationHandler::ConstructL |
315 // ----------------------------------------------------------------------------- |
321 // ----------------------------------------------------------------------------- |
318 { |
324 { |
319 PROFILE_DEBUG1( |
325 PROFILE_DEBUG1( |
320 "CSIPApnConfigurationHandler::ConstructL()" ) |
326 "CSIPApnConfigurationHandler::ConstructL()" ) |
321 |
327 |
322 User::LeaveIfError( iSocketSrv.Connect() ); |
328 User::LeaveIfError( iSocketSrv.Connect() ); |
323 |
329 iRepository = CRepository::NewL( KCRUidCmManager ); |
324 PROFILE_DEBUG1( |
330 PROFILE_DEBUG1( |
325 "CSIPApnConfigurationHandler::ConstructL() exit" ) |
331 "CSIPApnConfigurationHandler::ConstructL() exit" ) |
326 } |
332 } |
327 |
333 |
328 // ----------------------------------------------------------------------------- |
334 // ----------------------------------------------------------------------------- |
424 |
430 |
425 // ----------------------------------------------------------------------------- |
431 // ----------------------------------------------------------------------------- |
426 // CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL |
432 // CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL |
427 // ----------------------------------------------------------------------------- |
433 // ----------------------------------------------------------------------------- |
428 // |
434 // |
429 void CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL( TUint32 aIapId ) |
435 void CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL() |
430 { |
436 { |
431 PROFILE_DEBUG1( |
437 PROFILE_DEBUG1( |
432 "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL()" ) |
438 "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL()" ) |
433 |
439 |
434 Cancel(); |
440 Cancel(); |
435 |
441 |
436 if ( !iCommsDatabase ) |
442 if ( !iCommsDatabase ) |
437 { |
443 { |
438 PROFILE_DEBUG1( |
444 PROFILE_DEBUG1( |
439 "CSIPApnConfigurationHandler:: create commsdb" ) |
445 "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL create commsdb" ) |
440 iCommsDatabase = CCommsDatabase::NewL(); |
446 iCommsDatabase = CCommsDatabase::NewL(); |
441 } |
447 } |
442 |
448 |
443 PROFILE_DEBUG1( |
449 PROFILE_DEBUG1( |
444 "CSIPApnConfigurationHandler:: request notification" ) |
450 "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL request notification" ) |
445 |
451 |
446 // Start monitoring for db events, there will be lots of them pouring in |
452 // Start monitoring for db events, there will be lots of them pouring in |
447 // as there's no filtering feature. We are interested only in |
453 // as there's no filtering feature. We are interested only in |
448 // unlocked events. |
454 // unlocked events. |
|
455 |
|
456 if(iDBMonitoringRetryCount > KDBMaxRetryCount) |
|
457 { |
|
458 PROFILE_DEBUG1("CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL max retries reached!" ) |
|
459 User::Leave( KErrAbort ); |
|
460 } |
|
461 |
449 User::LeaveIfError( iCommsDatabase->RequestNotification( iStatus ) ); |
462 User::LeaveIfError( iCommsDatabase->RequestNotification( iStatus ) ); |
450 |
|
451 SetActive(); |
463 SetActive(); |
452 |
464 |
453 iIapId = aIapId; |
|
454 |
|
455 SetMonitoringState( EMonitoringDatabase ); |
465 SetMonitoringState( EMonitoringDatabase ); |
456 |
466 |
457 PROFILE_DEBUG1( |
467 PROFILE_DEBUG1( |
458 "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL(), exit" ) |
468 "CSIPApnConfigurationHandler::WatchDatabaseStatusChangeL(), exit" ) |
459 } |
469 } |
540 // monitoring for database events and retry apn changing at each |
550 // monitoring for database events and retry apn changing at each |
541 // unlock/rollback event. |
551 // unlock/rollback event. |
542 |
552 |
543 __ASSERT_ALWAYS( aAllowAsync, User::Leave( KErrInUse ) ); |
553 __ASSERT_ALWAYS( aAllowAsync, User::Leave( KErrInUse ) ); |
544 |
554 |
545 WatchDatabaseStatusChangeL( iIapId ); |
555 WatchDatabaseStatusChangeL(); |
546 } |
556 } |
547 else |
557 else |
548 { |
558 { |
549 User::LeaveIfError( err ); |
559 User::LeaveIfError( err ); |
550 apnChanged = ETrue; |
560 apnChanged = ETrue; |
568 PROFILE_DEBUG1( |
578 PROFILE_DEBUG1( |
569 "CSIPApnConfigurationHandler::ChangeApnL()" ) |
579 "CSIPApnConfigurationHandler::ChangeApnL()" ) |
570 |
580 |
571 using namespace CommsDat; |
581 using namespace CommsDat; |
572 |
582 |
573 CMDBSession* db = CMDBSession::NewL( CMDBSession::LatestVersion() ); |
583 CMDBSession* db = CMDBSession::NewL( KCDVersion1_1 ); |
574 CleanupStack::PushL( db ); |
584 CleanupStack::PushL( db ); |
|
585 |
|
586 db->OpenTransactionL(); |
|
587 CleanupStack::PushL(TCleanupItem(RollBackDBTransaction, db)); |
|
588 |
575 // Set attributes so that also protected iaps can be accessed |
589 // Set attributes so that also protected iaps can be accessed |
576 db->SetAttributeMask( ECDHidden | ECDProtectedWrite ); |
590 db->SetAttributeMask( ECDHidden | ECDProtectedWrite ); |
577 |
591 |
578 // Create an iap record |
592 // Create an iap record |
579 CCDIAPRecord* iapRecord = |
593 CCDIAPRecord* iapRecord = |
645 } |
659 } |
646 |
660 |
647 db->ClearAttributeMask( ECDHidden | ECDProtectedWrite ); |
661 db->ClearAttributeMask( ECDHidden | ECDProtectedWrite ); |
648 |
662 |
649 CleanupStack::PopAndDestroy( iapRecord ); |
663 CleanupStack::PopAndDestroy( iapRecord ); |
|
664 |
|
665 db->CommitTransactionL(); |
|
666 |
|
667 CleanupStack::Pop(); //cleanup item |
|
668 |
650 CleanupStack::PopAndDestroy( db ); |
669 CleanupStack::PopAndDestroy( db ); |
651 |
670 |
652 SendApnChangedNotificationL( aApn ); |
671 if (iCellularDataBlocked) |
|
672 { |
|
673 AllowCellularDataUsage(); |
|
674 } |
|
675 |
|
676 SendApnChangedNotificationL( aApn ); |
653 |
677 |
654 PROFILE_DEBUG1( |
678 PROFILE_DEBUG1( |
655 "CSIPApnConfigurationHandler::ChangeApnL(), exit" ) |
679 "CSIPApnConfigurationHandler::ChangeApnL(), exit" ) |
656 } |
680 } |
657 |
681 |
699 // ----------------------------------------------------------------------------- |
723 // ----------------------------------------------------------------------------- |
700 // |
724 // |
701 void CSIPApnConfigurationHandler::ConnectionMonitoringCompletedL( TInt aError ) |
725 void CSIPApnConfigurationHandler::ConnectionMonitoringCompletedL( TInt aError ) |
702 { |
726 { |
703 PROFILE_DEBUG3( |
727 PROFILE_DEBUG3( |
704 "CSIPApnConfigurationHandler:: progress.err", |
728 "CSIPApnConfigurationHandler::ConnectionMonitoringCompletedL progress.err", |
705 iProgress().iError ); |
729 iProgress().iError ); |
706 PROFILE_DEBUG3( |
730 PROFILE_DEBUG3( |
707 "CSIPApnConfigurationHandler:: progress.stage", |
731 "CSIPApnConfigurationHandler::ConnectionMonitoringCompletedL progress.stage", |
708 iProgress().iStage ); |
732 iProgress().iStage ); |
709 |
733 |
710 if ( !aError ) |
734 if ( !aError ) |
711 { |
735 { |
712 if ( iProgress().iStage == KConnectionClosed || |
736 if ( iProgress().iStage == KConnectionClosed || |
746 aError == RDbNotifier::ERollback || |
770 aError == RDbNotifier::ERollback || |
747 aError == RDbNotifier::EClose ) |
771 aError == RDbNotifier::EClose ) |
748 { |
772 { |
749 // Changing may be now possible, if not, db notifications or connection |
773 // Changing may be now possible, if not, db notifications or connection |
750 // monitoring is re-enabled inside following method |
774 // monitoring is re-enabled inside following method |
|
775 PROFILE_DEBUG1("DatabaseMonitoringCompletedL::DatabaseMonitoringCompletedL BlockCellularDataUsageL" ); |
|
776 BlockCellularDataUsageL(); |
751 apnChanged = ChangeApnIfNotInUseL(); |
777 apnChanged = ChangeApnIfNotInUseL(); |
752 } |
778 } |
753 else |
779 else |
754 { |
780 { |
755 WatchDatabaseStatusChangeL( iIapId ); |
781 iDBMonitoringRetryCount++; |
756 } |
782 WatchDatabaseStatusChangeL(); |
757 |
783 } |
758 // Have some safety limit for monitoring as it's not guaranteed that |
784 |
759 // db lock is ever released -> avoid unnecessary battery consumption |
785 if(apnChanged) |
760 if ( !apnChanged ) |
786 { |
761 { |
787 iDBMonitoringRetryCount = 0; |
762 iMonitoringRetryCount++; |
|
763 PROFILE_DEBUG3( |
|
764 "DatabaseMonitoringCompletedL:: retrycount", |
|
765 iMonitoringRetryCount ); |
|
766 |
|
767 if ( iMonitoringRetryCount > KSecondaryApnMaxRetryCount ) |
|
768 { |
|
769 PROFILE_DEBUG1( |
|
770 "CSIPApnConfigurationHandler:: max retries reached!" ) |
|
771 Cancel(); |
|
772 |
|
773 User::Leave( KErrAbort ); |
|
774 } |
|
775 } |
788 } |
776 } |
789 } |
777 |
790 |
778 // ----------------------------------------------------------------------------- |
791 // ----------------------------------------------------------------------------- |
779 // CSIPApnConfigurationHandler::SendApnChangedNotificationL |
792 // CSIPApnConfigurationHandler::SendApnChangedNotificationL |
900 delete iSecondaryApn; |
913 delete iSecondaryApn; |
901 iSecondaryApn = newApn; |
914 iSecondaryApn = newApn; |
902 } |
915 } |
903 } |
916 } |
904 |
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // CSIPApnConfigurationHandler::BlockCellularDataUsageL |
|
920 // ----------------------------------------------------------------------------- |
|
921 // |
|
922 void CSIPApnConfigurationHandler::BlockCellularDataUsageL() |
|
923 { |
|
924 PROFILE_DEBUG1("DatabaseMonitoringCompletedL::BlockCellularDataUsageL Enter" ); |
|
925 //Current Usage Status; |
|
926 iRepository->Get( KCurrentCellularDataUsage, iCurrentUsageStatus ); |
|
927 iRepository->Set( KCurrentCellularDataUsage, ECmCellularDataUsageDisabled ); |
|
928 iCellularDataBlocked = ETrue; |
|
929 PROFILE_DEBUG1("DatabaseMonitoringCompletedL::BlockCellularDataUsageL Exit" ); |
|
930 } |
|
931 // ----------------------------------------------------------------------------- |
|
932 // CSIPApnConfigurationHandler::AllowCellularDataUsage |
|
933 // ----------------------------------------------------------------------------- |
|
934 // |
|
935 void CSIPApnConfigurationHandler::AllowCellularDataUsage() |
|
936 { |
|
937 PROFILE_DEBUG1("DatabaseMonitoringCompletedL::AllowCellularDataUsage Enter" ); |
|
938 iRepository->Set( KCurrentCellularDataUsage, iCurrentUsageStatus ); |
|
939 iDBMonitoringRetryCount = 0; |
|
940 iCellularDataBlocked = EFalse; |
|
941 PROFILE_DEBUG1("DatabaseMonitoringCompletedL::AllowCellularDataUsage Exit" ); |
|
942 } |
|
943 |
|
944 // ----------------------------------------------------------------------------- |
|
945 // CSIPApnConfigurationHandler::RollBackDBTransaction |
|
946 // ----------------------------------------------------------------------------- |
|
947 // |
|
948 void CSIPApnConfigurationHandler::RollBackDBTransaction(TAny* aDb) |
|
949 { |
|
950 CMDBSession* db = static_cast<CMDBSession*>(aDb); |
|
951 TRAP_IGNORE(db->RollbackTransactionL()); |
|
952 } |
|
953 |
905 // End of file |
954 // End of file |