connectionmonitoring/connmon/connectionmonitor/src/cellulardatausagekeyupdater.cpp
branchRCL_3
changeset 55 fc7b30ed2058
parent 8 2e6c4614c58e
equal deleted inserted replaced
54:984e13af52c4 55:fc7b30ed2058
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    69 //
    69 //
    70 CCellularDataUsageKeyUpdater::~CCellularDataUsageKeyUpdater()
    70 CCellularDataUsageKeyUpdater::~CCellularDataUsageKeyUpdater()
    71     {
    71     {
    72     // Cancel outstanding request, if exists
    72     // Cancel outstanding request, if exists
    73     Cancel();
    73     Cancel();
    74     delete iRepository;
    74     delete iCommsRepository;
       
    75     delete iCmmRepository;
    75     }
    76     }
    76 
    77 
    77 // -----------------------------------------------------------------------------
    78 // -----------------------------------------------------------------------------
    78 // CCellularDataUsageKeyUpdater::UpdateKeyL
    79 // CCellularDataUsageKeyUpdater::UpdateKeyL
    79 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    80 //
    81 //
    81 void CCellularDataUsageKeyUpdater::UpdateKeyL( const TInt aRegistration ) const
    82 void CCellularDataUsageKeyUpdater::UpdateKeyL( const TInt aRegistration ) const
    82     {
    83     {
    83     LOGENTRFN("CCellularDataUsageKeyUpdater::UpdateKeyL()")
    84     LOGENTRFN("CCellularDataUsageKeyUpdater::UpdateKeyL()")
    84     LOGIT1("CCellularDataUsageKeyUpdater::UpdateKeyL: aRegistration <%d>", 
    85     LOGIT1("CCellularDataUsageKeyUpdater::UpdateKeyL: aRegistration <%d>",
    85             aRegistration)
    86             aRegistration)
    86                 
    87 
    87     TCmGenConnSettings occSettings = ReadGenConnSettingsL();
       
    88   
       
    89     TInt value( ECmCellularDataUsageDisabled );
    88     TInt value( ECmCellularDataUsageDisabled );
    90         
    89 
    91     if ( aRegistration == ENetworkRegistrationExtRoamingInternational )
    90     // If dial-up PDP context override is active, disable cellular data usage (temporarily).
    92         {           
    91     if ( iServer->GetDialUpOverrideStatus() != EConnMonDialUpOverrideActive )
    93         value = occSettings.iCellularDataUsageVisitor;
    92         {
    94         }
    93         TCmGenConnSettings occSettings = ReadGenConnSettingsL();
    95     else if ( aRegistration == ENetworkRegistrationExtHomeNetwork || 
    94 
    96               aRegistration == ENetworkRegistrationExtRoamingNational )
    95         if ( aRegistration == ENetworkRegistrationExtRoamingInternational )
    97         {           
    96             {
    98         value = occSettings.iCellularDataUsageHome;
    97             value = occSettings.iCellularDataUsageVisitor;
    99         }
    98             }
   100 
    99         else if ( aRegistration == ENetworkRegistrationExtHomeNetwork ||
   101     CRepository* cmRepository = NULL;
   100                   aRegistration == ENetworkRegistrationExtRoamingNational )
   102     
   101             {
   103     TRAPD( err, cmRepository = CRepository::NewL( KCRUidCmManager ) )
   102             value = occSettings.iCellularDataUsageHome;
   104     
   103             }
   105     if ( err == KErrNone )
   104         }
   106         {
   105 
   107         TInt previous( 0 );
   106     TInt previous( 0 );
   108         err = cmRepository->Get( KCurrentCellularDataUsage, previous );
   107     TInt err = iCmmRepository->Get( KCurrentCellularDataUsage, previous );
   109            
   108     if ( err == KErrNone && ( value != previous ) )
   110         if ( err == KErrNone && ( value != previous ) )
   109         {
   111             {
   110         iCmmRepository->Set( KCurrentCellularDataUsage, value );
   112             cmRepository->Set( KCurrentCellularDataUsage, value );
   111         LOGIT1("KCurrentCellularDataUsage set to %d", value)
   113             LOGIT1("KCurrentCellularDataUsage set to %d", value)
   112         }
       
   113     else
       
   114         {
       
   115         LOGIT2("KCurrentCellularDataUsage already up-to-date %d <%d>", previous, err)
       
   116         }
       
   117 
       
   118     LOGEXITFN("CCellularDataUsageKeyUpdater::UpdateKeyL()")
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // Return ETrue if dial-up PDP context override feature is enabled.
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 TBool CCellularDataUsageKeyUpdater::DialUpOverrideEnabled() const
       
   126     {
       
   127     LOGENTRFN("CCellularDataUsageKeyUpdater::DialUpOverrideEnabled()")
       
   128     TBool result( EFalse );
       
   129 
       
   130     if ( iCmmRepository )
       
   131         {
       
   132         TInt value( 0 );
       
   133         TInt err = iCmmRepository->Get( KDialUpOverride, value );
       
   134         if ( err == KErrNone )
       
   135             {
       
   136             if ( value )
       
   137                 {
       
   138                 result = ETrue;
       
   139                 LOGIT("ConstructL: Dial-up override enabled")
       
   140                 }
       
   141             else
       
   142                 {
       
   143                 LOGIT("ConstructL: Dial-up override disabled")
       
   144                 }
   114             }
   145             }
   115         else
   146         else
   116             {
   147             {
   117             LOGIT1("KCurrentCellularDataUsage already up-to-date %d", previous)
   148             LOGIT1("Failed to read KDialUpOverride-key from repository <%d>", err)
   118             }
   149             }
   119         
   150         }
   120         delete cmRepository;    
   151 
   121         }
   152     LOGEXITFN1("CCellularDataUsageKeyUpdater::DialUpOverrideEnabled()", result)
   122     else
   153     return result;
   123         {
       
   124         LOGIT1("CCRepository::NewL( KCRUidCmManager ) FAILED <%d>", err)
       
   125         }
       
   126 
       
   127     LOGEXITFN("CCellularDataUsageKeyUpdater::UpdateKeyL()")
       
   128     }
   154     }
   129 
   155 
   130 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   131 // CCellularDataUsageKeyUpdater::CCellularDataUsageKeyUpdater
   157 // CCellularDataUsageKeyUpdater::CCellularDataUsageKeyUpdater
   132 // -----------------------------------------------------------------------------
   158 // -----------------------------------------------------------------------------
   134 CCellularDataUsageKeyUpdater::CCellularDataUsageKeyUpdater( CConnMonServer* aServer )
   160 CCellularDataUsageKeyUpdater::CCellularDataUsageKeyUpdater( CConnMonServer* aServer )
   135         :
   161         :
   136         CActive( EConnMonPriorityNormal ),
   162         CActive( EConnMonPriorityNormal ),
   137         iServer( aServer )
   163         iServer( aServer )
   138     {
   164     {
   139     iRepository = NULL;
   165     iCommsRepository = NULL;
       
   166     iCmmRepository = NULL;
   140     iErrorCounter = 0;
   167     iErrorCounter = 0;
   141     }
   168     }
   142 
   169 
   143 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   144 // CCellularDataUsageKeyUpdater::ConstructL
   171 // CCellularDataUsageKeyUpdater::ConstructL
   145 // -----------------------------------------------------------------------------
   172 // -----------------------------------------------------------------------------
   146 //
   173 //
   147 void CCellularDataUsageKeyUpdater::ConstructL()
   174 void CCellularDataUsageKeyUpdater::ConstructL()
   148     {
   175     {
   149     iRepository = CRepository::NewL( KCDCommsRepositoryId );
   176     iCommsRepository = CRepository::NewL( KCDCommsRepositoryId );
   150     
   177 
       
   178     // Open CmManager central repository.
       
   179     TRAPD( err, iCmmRepository = CRepository::NewL( KCRUidCmManager ) )
       
   180     if ( err )
       
   181         {
       
   182         LOGIT1("CRepository::NewL( KCRUidCmManager ) FAILED <%d>", err)
       
   183         err = KErrNone;
       
   184         }
       
   185 
   151     // Find out Default connection table id.
   186     // Find out Default connection table id.
   152     // It contains iCellularDataUsageHome and iCellularDataUsageVisitor keys.
   187     // It contains iCellularDataUsageHome and iCellularDataUsageVisitor keys.
   153     CMDBSession* db = CMDBSession::NewLC( CMDBSession::LatestVersion() );	
   188     CMDBSession* db = CMDBSession::NewLC( CMDBSession::LatestVersion() );	
   154     TRAPD( err, iTableId = CCDDefConnRecord::TableIdL( *db ) )
   189     TRAP( err, iTableId = CCDDefConnRecord::TableIdL( *db ) )
   155     	
   190 
   156     if ( err )
   191     if ( err )
   157         {
   192         {
   158         LOGIT1("ERROR, CCDDefConnRecord::TableIdL() <%d>", err)
   193         LOGIT1("ERROR, CCDDefConnRecord::TableIdL() <%d>", err)
   159         // Default connection table did not exist. 
   194         // Default connection table did not exist. 
   160         // Try once more because CMManager might have created it.
   195         // Try once more because CMManager might have created it.
   174 // CCellularDataUsageKeyUpdater::RequestNotifications
   209 // CCellularDataUsageKeyUpdater::RequestNotifications
   175 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   176 //
   211 //
   177 TInt CCellularDataUsageKeyUpdater::RequestNotifications()
   212 TInt CCellularDataUsageKeyUpdater::RequestNotifications()
   178     {  	    	
   213     {  	    	
   179     LOGIT1("Calling iRepository->NotifyRequest() for table 0x%08X", iTableId)
   214     LOGIT1("Calling iCommsRepository->NotifyRequest() for table 0x%08X", iTableId)
   180     TInt err = iRepository->NotifyRequest( iTableId, KCDMaskShowRecordType, iStatus );
   215     TInt err = iCommsRepository->NotifyRequest( iTableId, KCDMaskShowRecordType, iStatus );
   181 
   216 
   182     if ( err == KErrNone )
   217     if ( err == KErrNone )
   183         {
   218         {
   184         SetActive();
   219         SetActive();
   185         }
   220         }
   186     else
   221     else
   187         {
   222         {
   188         LOGIT1("ERROR, iRepository->NotifyRequest() <%d>", err)
   223         LOGIT1("ERROR, iCommsRepository->NotifyRequest() <%d>", err)
   189         }
   224         }
   190 
   225 
   191     return err;
   226     return err;
   192     }
   227     }
   193 
   228 
   195 // CCellularDataUsageKeyUpdater::DoCancel
   230 // CCellularDataUsageKeyUpdater::DoCancel
   196 // -----------------------------------------------------------------------------
   231 // -----------------------------------------------------------------------------
   197 //
   232 //
   198 void CCellularDataUsageKeyUpdater::DoCancel()
   233 void CCellularDataUsageKeyUpdater::DoCancel()
   199     {
   234     {
   200     iRepository->NotifyCancel( iTableId, KCDMaskShowRecordType );
   235     iCommsRepository->NotifyCancel( iTableId, KCDMaskShowRecordType );
   201     }
   236     }
   202 
   237 
   203 // -----------------------------------------------------------------------------
   238 // -----------------------------------------------------------------------------
   204 // CCellularDataUsageKeyUpdater::RunL
   239 // CCellularDataUsageKeyUpdater::RunL
   205 // -----------------------------------------------------------------------------
   240 // -----------------------------------------------------------------------------