bearermanagement/mpm/src/mpmserver.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 27 489cf6208544
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
    24 #include <commdb.h>
    24 #include <commdb.h>
    25 #include <etel3rdparty.h>                // Voice call notification
    25 #include <etel3rdparty.h>                // Voice call notification
    26 #include <mmtsy_names.h>                 // KMmTsyModuleName
    26 #include <mmtsy_names.h>                 // KMmTsyModuleName
    27 #include <centralrepository.h>
    27 #include <centralrepository.h>
    28 #include <es_sock_partner.h>
    28 #include <es_sock_partner.h>
       
    29 #include <CoreApplicationUIsSDKCRKeys.h>
    29 
    30 
    30 #include "mpmserver.h"
    31 #include "mpmserver.h"
    31 #include "mpmserversession.h"
    32 #include "mpmserversession.h"
    32 #include "mpmconnmonevents.h"
    33 #include "mpmconnmonevents.h"
    33 #include "mpmlogger.h"
    34 #include "mpmlogger.h"
    37 #include "mpmconfirmdlgroaming.h"
    38 #include "mpmconfirmdlgroaming.h"
    38 #include "mpmconfirmdlgstarting.h"
    39 #include "mpmconfirmdlgstarting.h"
    39 #include "mpmdefaultconnection.h"
    40 #include "mpmdefaultconnection.h"
    40 #include "mpmcommsdataccess.h"
    41 #include "mpmcommsdataccess.h"
    41 #include "mpmwlanquerydialog.h"
    42 #include "mpmwlanquerydialog.h"
    42 #include "mpmdialog.h"
       
    43 #include "mpmprivatecrkeys.h"
    43 #include "mpmprivatecrkeys.h"
    44 #include "mpmcsidwatcher.h"
    44 #include "mpmcsidwatcher.h"
    45 #include "mpmdatausagewatcher.h"
    45 #include "mpmdatausagewatcher.h"
    46 #include "mpmpropertydef.h"
    46 #include "mpmpropertydef.h"
       
    47 #include "mpmofflinewatcher.h"
    47 
    48 
    48 // ============================= LOCAL FUNCTIONS ===============================
    49 // ============================= LOCAL FUNCTIONS ===============================
    49 
    50 
    50 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
    51 // PanicServer 
    52 // PanicServer 
    87       iWLANScanRequired( EFalse ), 
    88       iWLANScanRequired( EFalse ), 
    88       iDisconnectQueue( NULL ), 
    89       iDisconnectQueue( NULL ), 
    89       iRoamingQueue( NULL ), 
    90       iRoamingQueue( NULL ), 
    90       iStartingQueue( NULL ),
    91       iStartingQueue( NULL ),
    91       iWlanQueryQueue( NULL ),
    92       iWlanQueryQueue( NULL ),
    92       iConnectDialogQueue( NULL ),
       
    93       iDefaultConnection( NULL ), 
    93       iDefaultConnection( NULL ), 
    94       iConnectionCounter( 0 )
    94       iConnectionCounter( 0 ),
       
    95       iOfflineMode( ECoreAppUIsNetworkConnectionAllowed )
    95     {
    96     {
    96     }
    97     }
    97 
    98 
    98 
    99 
    99 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   108 
   109 
   109     // Connect to ETel server
   110     // Connect to ETel server
   110     // The RTelServer::Connect() might not always work with the first trial,
   111     // The RTelServer::Connect() might not always work with the first trial,
   111     // because of a coding error related to using semaphores in the method.
   112     // because of a coding error related to using semaphores in the method.
   112     TInt err( KErrNotReady );
   113     TInt err( KErrNotReady );
       
   114     err = iTelServer.Connect();
   113     TInt a = 0;
   115     TInt a = 0;
   114     while( a < KPhoneRetryCount && err != KErrNone )
   116     while( a < KPhoneRetryCount && err != KErrNone )
   115         {
   117         {
   116         User::After( KPhoneRetryTimeout );
   118         User::After( KPhoneRetryTimeout );
   117         err = iTelServer.Connect();
   119         err = iTelServer.Connect();
   161     iStartingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgStarting>( KGranularity ); 
   163     iStartingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgStarting>( KGranularity ); 
   162     iStartingQueue->Reset();
   164     iStartingQueue->Reset();
   163 
   165 
   164     iWlanQueryQueue = new ( ELeave ) CArrayPtrFlat<CMPMWlanQueryDialog>( KGranularity );
   166     iWlanQueryQueue = new ( ELeave ) CArrayPtrFlat<CMPMWlanQueryDialog>( KGranularity );
   165     iWlanQueryQueue->Reset();
   167     iWlanQueryQueue->Reset();
   166 
       
   167     iConnectDialogQueue = new ( ELeave ) CArrayPtrFlat<CMPMDialog>( KGranularity );
       
   168     iConnectDialogQueue->Reset();
       
   169     
   168     
   170     iDefaultConnection = CMPMDefaultConnection::NewL( this );    
   169     iDefaultConnection = CMPMDefaultConnection::NewL( this );    
   171 
   170 
   172     // Create central repository watcher and start it
   171     // Create central repository watcher and start it
   173     iMpmCsIdWatcher = CMpmCsIdWatcher::NewL();
   172     iMpmCsIdWatcher = CMpmCsIdWatcher::NewL();
   174     iMpmCsIdWatcher->StartL();
   173     iMpmCsIdWatcher->StartL();
   175 
   174 
   176     // Create another central repository watcher and start it
   175     // Create another central repository watcher and start it
   177     // TODO: Trapped, because currently it may fatally leave in HW.
       
   178     // (Possibly because of the capability updates of data usage watcher's CR-keys.)
       
   179     TRAPD( duwErr, iMpmDataUsageWatcher = CMpmDataUsageWatcher::NewL( this ) );
   176     TRAPD( duwErr, iMpmDataUsageWatcher = CMpmDataUsageWatcher::NewL( this ) );
   180     if (duwErr == KErrNone)
   177     if (duwErr == KErrNone)
   181         {
   178         {
   182         iMpmDataUsageWatcher->StartL();
   179         iMpmDataUsageWatcher->StartL();
   183         }
   180         }
   185         {
   182         {
   186         iMpmDataUsageWatcher = NULL;
   183         iMpmDataUsageWatcher = NULL;
   187         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmDataUsageWatcher::NewL() failed!" )
   184         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmDataUsageWatcher::NewL() failed!" )
   188         }
   185         }
   189 
   186 
   190     // Define P&S keys (snap & iap) for the user connection
   187     // Create another central repository watcher and start it
   191     TInt ret = RProperty::Define( KMPMUserConnectionCategory,
   188     TRAPD( owErr, iMpmOfflineWatcher = CMpmOfflineWatcher::NewL( this ) );
   192                                   KMPMPSKeyUserConnectionSnap,
   189     if (owErr == KErrNone)
   193                                   KMPMUserConnectionSnapType,
   190         {
   194                                   KMPMUserConnectionReadPolicy,
   191         iMpmOfflineWatcher->StartL();
   195                                   KMPMUserConnectionWritePolicy );
   192         }
   196     
   193     else
   197     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
   194         {
   198         {
   195         iMpmOfflineWatcher = NULL;
   199         User::Leave(err);
   196         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmOfflineWatcher::NewL() failed!" )
   200         }
   197         }
   201     
       
   202     ret = RProperty::Define( KMPMUserConnectionCategory,
       
   203                              KMPMPSKeyUserConnectionIap,
       
   204                              KMPMUserConnectionIapType,
       
   205                              KMPMUserConnectionReadPolicy,
       
   206                              KMPMUserConnectionWritePolicy );
       
   207                                           
       
   208     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   209         {
       
   210         User::Leave(err);
       
   211         }
       
   212 
       
   213     // Set initial values for the keys
       
   214     User::LeaveIfError(RProperty::Set( KMPMUserConnectionCategory,
       
   215                                        KMPMPSKeyUserConnectionSnap,
       
   216                                        0 ));
       
   217 
       
   218     User::LeaveIfError(RProperty::Set( KMPMUserConnectionCategory,
       
   219                                        KMPMPSKeyUserConnectionIap,
       
   220                                        0 ));
       
   221 
   198 
   222     // Read dedicated clients from the central repository
   199     // Read dedicated clients from the central repository
   223     CRepository* repository = CRepository::NewL( KCRUidMPM );
   200     CRepository* repository = CRepository::NewL( KCRUidMPM );
   224     
   201     
   225     CleanupStack::PushL( repository );
   202     CleanupStack::PushL( repository );
   226     
   203     
   227     TUint32 baseKey = KMpmDedicatedClientBase;
   204     TUint32 baseKey = KMpmDedicatedClientBase;
   228     TInt value;
   205     TInt value;
   229     ret = KErrNone;
   206     TInt ret = KErrNone;
   230     
   207     
   231     while ( ret == KErrNone )
   208     while ( ret == KErrNone )
   232         {
   209         {
   233         ret = repository->Get ( baseKey, value );
   210         ret = repository->Get ( baseKey, value );
   234 
   211 
   240 
   217 
   241         baseKey++;
   218         baseKey++;
   242         }
   219         }
   243     
   220     
   244     CleanupStack::PopAndDestroy ( repository );
   221     CleanupStack::PopAndDestroy ( repository );
   245     
       
   246     // Define P&S keys for the connection dialogs
       
   247     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   248                              KMPMPSKeyActiveConnectionIap,
       
   249                              KMPMActiveConnectionIapType,
       
   250                              KMPMActiveConnectionReadPolicy,
       
   251                              KMPMActiveConnectionWritePolicy );
       
   252     
       
   253     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   254         {
       
   255         User::Leave(err);
       
   256         }
       
   257     
       
   258     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   259                              KMPMPSKeyActiveConnectionSnap,
       
   260                              KMPMActiveConnectionSnapType,
       
   261                              KMPMActiveConnectionReadPolicy,
       
   262                              KMPMActiveConnectionWritePolicy );
       
   263     
       
   264     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   265         {
       
   266         User::Leave(err);
       
   267         }
       
   268 
       
   269     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   270                              KMPMPSKeyActiveConnectionBearer,
       
   271                              KMPMActiveConnectionBearerType,
       
   272                              KMPMActiveConnectionReadPolicy,
       
   273                              KMPMActiveConnectionWritePolicy );
       
   274                                           
       
   275     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   276         {
       
   277         User::Leave(err);
       
   278         }
       
   279         
   222         
   280     PublishActiveConnection();
   223     iConnUiUtils = CConnectionUiUtilities::NewL();
   281     }
   224     }
   282 
   225 
   283 
   226 
   284 // -----------------------------------------------------------------------------
   227 // -----------------------------------------------------------------------------
   285 // CMPMServer::~CMPMServer
   228 // CMPMServer::~CMPMServer
   308     while ( iWlanQueryQueue && iWlanQueryQueue->Count() > 0 )
   251     while ( iWlanQueryQueue && iWlanQueryQueue->Count() > 0 )
   309         {
   252         {
   310         iWlanQueryQueue->Delete( 0 );
   253         iWlanQueryQueue->Delete( 0 );
   311         }
   254         }
   312     delete iWlanQueryQueue;
   255     delete iWlanQueryQueue;
   313     
       
   314     if ( iConnectDialogQueue )
       
   315         {
       
   316         iConnectDialogQueue->ResetAndDestroy();
       
   317         }
       
   318     delete iConnectDialogQueue;
       
   319 
   256 
   320     delete iEvents;
   257     delete iEvents;
   321 
   258 
   322     for ( TInt i = 0; i < iBlackListIdList.Count(); i++ )
   259     for ( TInt i = 0; i < iBlackListIdList.Count(); i++ )
   323         {
   260         {
   342     delete iDefaultConnection;
   279     delete iDefaultConnection;
   343     
   280     
   344     delete iMpmCsIdWatcher;    
   281     delete iMpmCsIdWatcher;    
   345     
   282     
   346     delete iMpmDataUsageWatcher;    
   283     delete iMpmDataUsageWatcher;    
   347     
   284 
       
   285     delete iMpmOfflineWatcher;    
       
   286 
   348     iDedicatedClients.Close();
   287     iDedicatedClients.Close();
   349 
   288 
   350     delete iCommsDatAccess;    
   289     delete iCommsDatAccess;
       
   290     
       
   291     delete iConnUiUtils;
   351     }
   292     }
   352 
   293 
   353 
   294 
   354 // -----------------------------------------------------------------------------
   295 // -----------------------------------------------------------------------------
   355 // CMPMServer::NewSessionL
   296 // CMPMServer::NewSessionL
   415     TConnectionInfo connInfo;
   356     TConnectionInfo connInfo;
   416     connInfo.iConnId = aConnId;
   357     connInfo.iConnId = aConnId;
   417     connInfo.iSnap   = aSnap;
   358     connInfo.iSnap   = aSnap;
   418     connInfo.iIapId  = aIapId;
   359     connInfo.iIapId  = aIapId;
   419     connInfo.iState  = aState;
   360     connInfo.iState  = aState;
       
   361     connInfo.iAppUid = aSession.AppUid();
   420 
   362 
   421     // Package into TActiveBMConn //TODO Redundant.. remove the other one.
   363     // Package into TActiveBMConn //TODO Redundant.. remove the other one.
   422     // 
   364     // 
   423     TActiveBMConn conn;
   365     TActiveBMConn conn;
   424     conn.iConnInfo          = connInfo;
   366     conn.iConnInfo          = connInfo;
   443             iActiveBMConns[index1].iConnInfo.iState = aState;
   385             iActiveBMConns[index1].iConnInfo.iState = aState;
   444             iActiveBMConns[index1].iConnInfo.iAppUid = aSession.AppUid();
   386             iActiveBMConns[index1].iConnInfo.iAppUid = aSession.AppUid();
   445             }
   387             }
   446         }
   388         }
   447 
   389 
   448     if ( aState == EStarted )
       
   449         {
       
   450         TInt ret = KErrNone;
       
   451         
       
   452         TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   453         
       
   454         if ( ret != KErrNone )
       
   455             {
       
   456             iActiveBearerType = EMPMBearerTypeNone;
       
   457             iActiveIapId = 0;
       
   458             iActiveSnapId = 0;            
       
   459             }
       
   460         }
       
   461 
       
   462 #ifdef _DEBUG
   390 #ifdef _DEBUG
   463     // Dump array of active connections to log in order to support testing.
   391     // Dump array of active connections to log in order to support testing.
   464     // 
   392     // 
   465     DumpActiveBMConns();
   393     DumpActiveBMConns();
   466 #endif // _DEBUG
   394 #endif // _DEBUG
   471 // CMPMServer::ResetBMConnection
   399 // CMPMServer::ResetBMConnection
   472 // -----------------------------------------------------------------------------
   400 // -----------------------------------------------------------------------------
   473 //
   401 //
   474 void CMPMServer::ResetBMConnection( const TConnectionId aConnId,
   402 void CMPMServer::ResetBMConnection( const TConnectionId aConnId,
   475                                     const TUint32       aIapId,
   403                                     const TUint32       aIapId,
   476                                     CMPMServerSession&  aSession )
   404                                     CMPMServerSession&  /*aSession*/ )
   477     {
   405     {
   478     MPMLOGSTRING3(
   406     MPMLOGSTRING3(
   479         "CMPMServer::ResetBMConnection - aConnId = 0x%x, aIapId = %i", 
   407         "CMPMServer::ResetBMConnection - aConnId = 0x%x, aIapId = %i", 
   480         aConnId, aIapId )
   408         aConnId, aIapId )
   481 
   409 
   507         // relationship in a database entry and that this entry survives 
   435         // relationship in a database entry and that this entry survives 
   508         // a roaming event (an ApplicationLeavesConnection call).
   436         // a roaming event (an ApplicationLeavesConnection call).
   509         //
   437         //
   510         iActiveBMConns[index1].iConnInfo.iIapId = 0;
   438         iActiveBMConns[index1].iConnInfo.iIapId = 0;
   511         iActiveBMConns[index1].iConnInfo.iState = EIdle;
   439         iActiveBMConns[index1].iConnInfo.iState = EIdle;
   512         
       
   513         // Change state of P&S keys if needed
       
   514         TInt ret = KErrNone;
       
   515         
       
   516         TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   517         
       
   518         if ( ret != KErrNone )
       
   519             {
       
   520             iActiveBearerType = EMPMBearerTypeNone;
       
   521             iActiveIapId = 0;
       
   522             iActiveSnapId = 0;            
       
   523             }
       
   524         }
   440         }
   525 #ifdef _DEBUG
   441 #ifdef _DEBUG
   526     // Dump array of active connections to log in order to support testing.
   442     // Dump array of active connections to log in order to support testing.
   527     // 
   443     // 
   528     DumpActiveBMConns();
   444     DumpActiveBMConns();
   533 // -----------------------------------------------------------------------------
   449 // -----------------------------------------------------------------------------
   534 // CMPMServer::RemoveBMConnection
   450 // CMPMServer::RemoveBMConnection
   535 // -----------------------------------------------------------------------------
   451 // -----------------------------------------------------------------------------
   536 //
   452 //
   537 void CMPMServer::RemoveBMConnection( const TConnectionId aConnId,
   453 void CMPMServer::RemoveBMConnection( const TConnectionId aConnId,
   538                                      CMPMServerSession&  aSession )
   454                                      CMPMServerSession&  /*aSession*/ )
   539     {
   455     {
   540     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   456     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   541         aConnId )
   457         aConnId )
   542 
   458 
   543     TInt count = iActiveBMConns.Count();
   459     TInt count = iActiveBMConns.Count();
   555         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   471         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   556             {
   472             {
   557             // If Connection Id found, remove it. 
   473             // If Connection Id found, remove it. 
   558             //
   474             //
   559             iActiveBMConns.Remove( i );
   475             iActiveBMConns.Remove( i );
   560 
       
   561             // Update active connection
       
   562             TInt ret = KErrNone;
       
   563         
       
   564             TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   565         
       
   566             if ( ret != KErrNone )
       
   567                 {
       
   568                 iActiveBearerType = EMPMBearerTypeNone;
       
   569                 iActiveIapId = 0;
       
   570                 iActiveSnapId = 0;            
       
   571                 }
       
   572             }
   476             }
   573         }
   477         }
   574 
   478 
   575 #ifdef _DEBUG
   479 #ifdef _DEBUG
   576     // Dump array of active connections to log in order to support testing.
   480     // Dump array of active connections to log in order to support testing.
   701 
   605 
   702 // -----------------------------------------------------------------------------
   606 // -----------------------------------------------------------------------------
   703 // CMPMServer::CheckIfStarted
   607 // CMPMServer::CheckIfStarted
   704 // -----------------------------------------------------------------------------
   608 // -----------------------------------------------------------------------------
   705 //
   609 //
   706 TBool CMPMServer::CheckIfStarted( const TUint32 aIapId )
   610 TBool CMPMServer::CheckIfStarted( const TUint32 aIapId , 
   707     {
   611                                   const TConnectionId aConnId )
   708     MPMLOGSTRING2( "CMPMServer::CheckIfStarted - aIapId = %i", aIapId )
   612     {
       
   613     MPMLOGSTRING3( "CMPMServer::CheckIfStarted - aIapId = %i, aConnId = 0x%x", 
       
   614                   aIapId, aConnId )
   709 
   615 
   710     TConnectionState state( EIdle );
   616     TConnectionState state( EIdle );
   711     TBool stopLoop( EFalse );
   617     TBool stopLoop( EFalse );
   712 
   618 
   713     // Loop all connections until EStarted is found or no more connections
   619     // Loop all connections until EStarted is found or no more connections
   714     // 
   620     // 
   715     for ( TInt i = 0; ( ( i < iActiveBMConns.Count() ) && !stopLoop ); i++ )
   621     for ( TInt i = 0; ( ( i < iActiveBMConns.Count() ) && !stopLoop ); i++ )
   716         {
   622         {
   717         // Check if IAP Id matches
   623         // Check if IAP Id matches; exclude matching with own connection
   718         // 
   624         // 
   719         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
   625         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId && 
       
   626              iActiveBMConns[i].iConnInfo.iConnId != aConnId)
   720             {
   627             {
   721             state = iActiveBMConns[i].iConnInfo.iState;  
   628             state = iActiveBMConns[i].iConnInfo.iState;  
   722 
   629 
   723             // Stop looping if EStarted found
   630             // Stop looping if EStarted found
   724             // 
   631             // 
   757             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Unknown" )
   664             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Unknown" )
   758             break;
   665             break;
   759             }
   666             }
   760         }
   667         }
   761 #endif // _DEBUG
   668 #endif // _DEBUG
   762 
   669         
   763     if ( state == EStarted )
   670     //Return true incase the matching connection is in EStarting state also because
       
   671     //sometimes when connections are started simultaneously (for same iapID) 
       
   672     //the first connection may still be in EStarting state. 
       
   673     //
       
   674     if ( state == EStarted || state == EStarting )
   764         {
   675         {
   765         return ETrue;
   676         return ETrue;
   766         }
   677         }
   767     else
   678     else
   768         {
   679         {
   847                 iActiveBMConns[i].iConnInfo.iState = EStarted;
   758                 iActiveBMConns[i].iConnInfo.iState = EStarted;
   848                 }
   759                 }
   849             }
   760             }
   850         }
   761         }
   851 
   762 
   852     TInt ret = KErrNone;
       
   853         
       
   854     TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   855         
       
   856     if ( ret != KErrNone )
       
   857         {
       
   858         iActiveBearerType = EMPMBearerTypeNone;
       
   859         iActiveIapId = 0;
       
   860         iActiveSnapId = 0;            
       
   861         }
       
   862 
       
   863 #ifdef _DEBUG
   763 #ifdef _DEBUG
   864     // Dump array of active connections to log in order to support testing.
   764     // Dump array of active connections to log in order to support testing.
   865     // 
   765     // 
   866     DumpActiveBMConns();
   766     DumpActiveBMConns();
   867 #endif // _DEBUG
   767 #endif // _DEBUG
   872 // CMPMServer::RemoveBMIAPConnection
   772 // CMPMServer::RemoveBMIAPConnection
   873 // -----------------------------------------------------------------------------
   773 // -----------------------------------------------------------------------------
   874 //
   774 //
   875 void CMPMServer::RemoveBMIAPConnection( const TUint32       aIapId, 
   775 void CMPMServer::RemoveBMIAPConnection( const TUint32       aIapId, 
   876                                         const TConnectionId aConnId,
   776                                         const TConnectionId aConnId,
   877                                         CMPMServerSession&  aSession )
   777                                         CMPMServerSession&  /*aSession*/ )
   878     {
   778     {
   879     MPMLOGSTRING3(
   779     MPMLOGSTRING3(
   880         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   780         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   881         aIapId, aConnId )
   781         aIapId, aConnId )
   882 
   782 
   918                     {
   818                     {
   919                     iActiveBMConns[i].iConnInfo.iIapId = 0;
   819                     iActiveBMConns[i].iConnInfo.iIapId = 0;
   920                     iActiveBMConns[i].iConnInfo.iState = EIdle;
   820                     iActiveBMConns[i].iConnInfo.iState = EIdle;
   921                     }
   821                     }
   922                 }
   822                 }
   923             
       
   924             // Update active connection
       
   925             TInt ret = KErrNone;
       
   926         
       
   927             TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   928         
       
   929             if ( ret != KErrNone )
       
   930                 {
       
   931                 iActiveBearerType = EMPMBearerTypeNone;
       
   932                 iActiveIapId = 0;
       
   933                 iActiveSnapId = 0;            
       
   934                 }
       
   935             }
   823             }
   936         }
   824         }
   937 
   825 
   938 #ifdef _DEBUG
   826 #ifdef _DEBUG
   939     // Dump array of active connections to log in order to support testing.
   827     // Dump array of active connections to log in order to support testing.
  1004     for ( TInt i = 0; i < iSessions.Count(); i++ )
   892     for ( TInt i = 0; i < iSessions.Count(); i++ )
  1005         {
   893         {
  1006         iapInfo = iSessions[i]->GetAvailableIAPs( );
   894         iapInfo = iSessions[i]->GetAvailableIAPs( );
  1007         iSessions[i]->PrefIAPNotificationL( iapInfo, aCaller );
   895         iSessions[i]->PrefIAPNotificationL( iapInfo, aCaller );
  1008         }
   896         }
  1009 
   897     }
  1010     // If a session is displaying connection selection dialog 
   898 
  1011     // the contents of the dialog should be updated according to the 
       
  1012     // current iap availability
       
  1013     //
       
  1014     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
       
  1015         {
       
  1016         iSessions[i]->UpdateConnectionDialogL();
       
  1017         }
       
  1018     }
       
  1019 
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // CMPMServer::UpdateSessionConnectionDlgL
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 void CMPMServer::UpdateSessionConnectionDlgL()
       
  1025     {
       
  1026     MPMLOGSTRING( "CMPMServer::UpdateSessionConnectionDlgL" )
       
  1027 
       
  1028     // If a session is displaying connection selection dialog 
       
  1029     // the contents of the dialog should be updated according to the 
       
  1030     // current iap availability
       
  1031     //
       
  1032     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
       
  1033         {
       
  1034         iSessions[i]->UpdateConnectionDialogL();
       
  1035         }
       
  1036     }
       
  1037 
   899 
  1038 // -----------------------------------------------------------------------------
   900 // -----------------------------------------------------------------------------
  1039 // CMPMServer::HandleServerBlackListIap
   901 // CMPMServer::HandleServerBlackListIap
  1040 // -----------------------------------------------------------------------------
   902 // -----------------------------------------------------------------------------
  1041 //
   903 //
  1117     if ( found )
   979     if ( found )
  1118         {
   980         {
  1119         // found blacklisted Connection Id
   981         // found blacklisted Connection Id
  1120         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
   982         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
  1121         iBlackListIdList.Remove( i ); // remove from the list 
   983         iBlackListIdList.Remove( i ); // remove from the list 
       
   984         
       
   985         MPMLOGSTRING2( "CMPMServer::HandleServerUnblackListIap - \
       
   986 connIdInfo count: %d", connIdInfo.Count() )
  1122 
   987 
  1123         if ( aIapId == 0 )
   988         if ( aIapId == 0 )
  1124             { // 0 will reset Connection Id blacklisted iap list 
   989             { // 0 will reset Connection Id blacklisted iap list 
       
   990             MPMLOGSTRING( "CMPMServer::HandleServerUnblackListIap - \
       
   991 reset Connection Id blacklisted iap list" )
       
   992 
  1125             connIdInfo.Close();
   993             connIdInfo.Close();
  1126             return KErrNone;
   994             return KErrNone;
  1127             }
   995             }
  1128 
   996 
  1129         found = EFalse;
   997         found = EFalse;
  1131             {
   999             {
  1132             if ( connIdInfo.Iap( j ) == aIapId )
  1000             if ( connIdInfo.Iap( j ) == aIapId )
  1133                 {
  1001                 {
  1134                 // found and remove blacklisted iap
  1002                 // found and remove blacklisted iap
  1135                 connIdInfo.Remove( j ); 
  1003                 connIdInfo.Remove( j ); 
       
  1004                 MPMLOGSTRING2( "CMPMServer::HandleServerUnblackListIap - \
       
  1005 removed blacklisted iap in index = %d", j )
       
  1006                 
  1136                 if ( connIdInfo.Count() == 0 )
  1007                 if ( connIdInfo.Count() == 0 )
  1137                     {
  1008                     {
  1138                     return KErrNone;
  1009                     return KErrNone;
  1139                     }
  1010                     }
  1140 
  1011 
  1148         iBlackListIdList.Insert( connIdInfo, 0 ); 
  1019         iBlackListIdList.Insert( connIdInfo, 0 ); 
  1149         return KErrNotFound;
  1020         return KErrNotFound;
  1150         }
  1021         }
  1151     else
  1022     else
  1152         {
  1023         {
       
  1024         MPMLOGSTRING( "CMPMServer::HandleServerUnblackListIap - \
       
  1025 not found blacklisted Connection Id" )
  1153         return KErrNotFound;
  1026         return KErrNotFound;
  1154         }
  1027         }
  1155     }
  1028     }
  1156 
  1029 
  1157 // -----------------------------------------------------------------------------
  1030 // -----------------------------------------------------------------------------
  1159 // -----------------------------------------------------------------------------
  1032 // -----------------------------------------------------------------------------
  1160 //
  1033 //
  1161 void CMPMServer::HandleServerUnblackListIap( 
  1034 void CMPMServer::HandleServerUnblackListIap( 
  1162     TBlacklistCategory  aCategory )
  1035     TBlacklistCategory  aCategory )
  1163     {
  1036     {
  1164     MPMLOGSTRING2( "CMPMServer::HandleServerUnblackListIap -\
  1037     MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap -\
  1165  aCategory = %i", aCategory )
  1038 aCategory = %i blacklisted Id count = %d", 
       
  1039                    aCategory, iBlackListIdList.Count() )
  1166 
  1040 
  1167     for( TInt i( 0 ); i < iBlackListIdList.Count(); i++ )
  1041     for( TInt i( 0 ); i < iBlackListIdList.Count(); i++ )
  1168         {
  1042         {
  1169         // found blacklisted Connection Id
  1043         // found blacklisted Connection Id
  1170         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
  1044         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
  1171         iBlackListIdList.Remove( i ); // remove from the list 
  1045         iBlackListIdList.Remove( i ); // remove from the list 
  1172 
  1046 
       
  1047         MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap - \
       
  1048 aConnId = 0x%x, blacklisted IapId count = %d", connIdInfo.iConnId, 
       
  1049         connIdInfo.Count() )
       
  1050         
  1173         for (TInt j = 0; j < connIdInfo.Count(); j++)
  1051         for (TInt j = 0; j < connIdInfo.Count(); j++)
  1174             {
  1052             {
  1175             if ( connIdInfo.Category( j ) == aCategory ) 
  1053             if ( connIdInfo.Category( j ) == aCategory ) 
  1176                 {
  1054                 {
  1177                 // found and remove blacklisted iap
  1055                 // found and remove blacklisted iap
       
  1056                 MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap - \
       
  1057 removed blacklisted iap id %i in index: %d", connIdInfo.Iap( j ), j )
  1178                 connIdInfo.Remove( j ); 
  1058                 connIdInfo.Remove( j ); 
  1179                 }
  1059                 }
  1180             }
  1060             }
  1181         // If any blacklisted iaps remain reinsert at the 
  1061         // If any blacklisted iaps remain reinsert at the 
  1182         // beginning connIdInfo to reflect activeness
  1062         // beginning connIdInfo to reflect activeness
  1183         //
  1063         //
  1184         if( connIdInfo.Count() > 0 )
  1064         if( connIdInfo.Count() > 0 )
  1185             {
  1065             {
       
  1066             MPMLOGSTRING( "reinsert connIdInfo to reflect activeness" )
  1186             iBlackListIdList.Insert( connIdInfo, 0 );             
  1067             iBlackListIdList.Insert( connIdInfo, 0 );             
  1187             }
  1068             }
  1188         }
  1069         }
  1189     }
  1070     }
  1190 
  1071 
  1520 // CMPMServer::StopConnections
  1401 // CMPMServer::StopConnections
  1521 // -----------------------------------------------------------------------------
  1402 // -----------------------------------------------------------------------------
  1522 //
  1403 //
  1523 void CMPMServer::StopConnections( TInt aIapId )
  1404 void CMPMServer::StopConnections( TInt aIapId )
  1524     {
  1405     {
       
  1406     MPMLOGSTRING2( "CMPMServer::StopConnections aIapId = %d", aIapId )
  1525     for (TInt index = 0; index < iSessions.Count(); index++)
  1407     for (TInt index = 0; index < iSessions.Count(); index++)
  1526         {
  1408         {
  1527 /*        if (iSessions[index]->UserConnection())
  1409         CMPMServerSession* session = iSessions[index];
  1528             continue;
       
  1529   */          
       
  1530         // Stop connection
  1410         // Stop connection
  1531         if ( aIapId == 0 )
  1411         if ( aIapId == 0 )
  1532             {
  1412             {
  1533             iSessions[index]->StopConnection();
  1413             session->StopConnection();
  1534             }
  1414             }
  1535         else
  1415         else if ( GetBMIap( session->ConnectionId() ) == aIapId )
  1536             {
  1416             {
  1537             TRAP_IGNORE( iSessions[index]->StopIAPNotificationL( aIapId ));
  1417             TRAP_IGNORE( session->StopIAPNotificationL( aIapId ));
  1538             }
  1418             }     
  1539         
  1419         }
  1540         }
       
  1541     }
       
  1542 
       
  1543 // -----------------------------------------------------------------------------
       
  1544 // CMPMServer::UpdateActiveConnectionL
       
  1545 // -----------------------------------------------------------------------------
       
  1546 //
       
  1547 void CMPMServer::UpdateActiveConnectionL( CMPMServerSession& aSession )
       
  1548     {
       
  1549     MPMLOGSTRING( "CMPMServer::UpdateActiveConnectionL" )
       
  1550     TUint32 snapId;
       
  1551 
       
  1552     if ( !NumberOfActiveConnections() )
       
  1553         {
       
  1554         // If no active connections then just reset keys and publish
       
  1555         iActiveBearerType = EMPMBearerTypeNone;
       
  1556         iActiveIapId = 0;
       
  1557         iActiveSnapId = 0;
       
  1558         PublishActiveConnection();
       
  1559         return;
       
  1560         }
       
  1561 
       
  1562     // Check if all active connections are in same snap
       
  1563     if ( CommsDatAccess()->AreActiveIapsInSameSnapL(
       
  1564          iActiveBMConns, snapId ) )
       
  1565         {
       
  1566         // Select active connection according to priority
       
  1567         CommsDatAccess()->SelectActiveConnectionL (
       
  1568             snapId,
       
  1569             iActiveBMConns,
       
  1570             iActiveIapId,
       
  1571             iActiveSnapId,
       
  1572             iActiveBearerType,
       
  1573             aSession );
       
  1574 
       
  1575         PublishActiveConnection();
       
  1576         return;
       
  1577         }
       
  1578 
       
  1579     // Reset active connections
       
  1580     iActiveBearerType = EMPMBearerTypeNone;
       
  1581     iActiveIapId = 0;
       
  1582     iActiveSnapId = 0;
       
  1583             
       
  1584     // Active connections locating in different snaps
       
  1585     // Use priority order vpn, wlan and packet
       
  1586     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1587         {
       
  1588         CMPMServerSession* serverSession = GetServerSession(
       
  1589             iActiveBMConns[index].iConnInfo.iConnId );
       
  1590                      	
       
  1591         // Do check only for active connections
       
  1592         if ( iActiveBMConns[index].iConnInfo.iState == EStarted &&
       
  1593         	   serverSession->ChooseBestIapCalled() )
       
  1594             {
       
  1595             TMPMBearerType bearerType = EMPMBearerTypeOther;
       
  1596         
       
  1597             if ( iDedicatedClients.Find( iActiveBMConns[index].iConnInfo.iAppUid ) == 
       
  1598                  KErrNone )
       
  1599                 {
       
  1600                 // Skip dedicated client
       
  1601                 continue;
       
  1602                 }
       
  1603 
       
  1604             bearerType = CommsDatAccess()->GetBearerTypeL( 
       
  1605                          iActiveBMConns[index].iConnInfo.iIapId );
       
  1606         
       
  1607             if ( bearerType == EMPMBearerTypeOther )
       
  1608                 {
       
  1609                 // Don't publish this connection
       
  1610                 continue;
       
  1611                 }
       
  1612                     
       
  1613             // This is true if,
       
  1614             // bearer type is smaller or different than none
       
  1615             // or
       
  1616             // bearer type is same and iap is different.
       
  1617             if ( ( bearerType < iActiveBearerType ) || 
       
  1618                  ( iActiveBearerType == EMPMBearerTypeNone ) ||
       
  1619                  ( ( bearerType == iActiveBearerType) &&
       
  1620                    ( iActiveIapId != iActiveBMConns[index].iConnInfo.iIapId ) ) )
       
  1621                 {
       
  1622                 iActiveBearerType = bearerType;
       
  1623                 iActiveIapId = iActiveBMConns[index].iConnInfo.iIapId;
       
  1624                 iActiveSnapId = iActiveBMConns[index].iConnInfo.iSnap;
       
  1625                 }
       
  1626             }
       
  1627 
       
  1628         PublishActiveConnection();  
       
  1629         }
       
  1630     }
       
  1631 
       
  1632 // -----------------------------------------------------------------------------
       
  1633 // CMPMServer::MapBearerType
       
  1634 // -----------------------------------------------------------------------------
       
  1635 //
       
  1636 TUint32 CMPMServer::MapBearerType(TMPMBearerType aBearerType)
       
  1637     {
       
  1638     MPMLOGSTRING( "CMPMServer::MapBearerType" )
       
  1639     
       
  1640     switch ( aBearerType )
       
  1641         {
       
  1642         case EMPMBearerTypeNone:
       
  1643             return 0;
       
  1644 
       
  1645         case EMPMBearerTypeVpn:
       
  1646             return KCommDbBearerVirtual;
       
  1647             
       
  1648         case EMPMBearerTypeWlan:
       
  1649             return KCommDbBearerWLAN;
       
  1650             
       
  1651         case EMPMBearerTypePacketData:
       
  1652             return KCommDbBearerWcdma;
       
  1653 
       
  1654         case EMPMBearerTypeOther:
       
  1655             return KCommDbBearerUnknown;
       
  1656             
       
  1657         default:
       
  1658             MPMLOGSTRING( "CMPMServer::MapBearerType: Unknown bearer type" )
       
  1659             break;
       
  1660         }
       
  1661     
       
  1662     return KCommDbBearerUnknown;
       
  1663     }
       
  1664 
       
  1665 // -----------------------------------------------------------------------------
       
  1666 // CMPMServer::PublishActiveConnection
       
  1667 // -----------------------------------------------------------------------------
       
  1668 //
       
  1669 void CMPMServer::PublishActiveConnection()
       
  1670     {
       
  1671     MPMLOGSTRING( "CMPMServer::PublishActiveConnection" )
       
  1672     
       
  1673     // update active connection keys
       
  1674     RProperty::Set( KMPMActiveConnectionCategory,
       
  1675                     KMPMPSKeyActiveConnectionIap,
       
  1676                     iActiveIapId );
       
  1677 
       
  1678     RProperty::Set( KMPMActiveConnectionCategory,
       
  1679                     KMPMPSKeyActiveConnectionSnap,
       
  1680                     iActiveSnapId );
       
  1681 
       
  1682     RProperty::Set( KMPMActiveConnectionCategory,
       
  1683                     KMPMPSKeyActiveConnectionBearer,
       
  1684                     MapBearerType( iActiveBearerType ) );    
       
  1685 
       
  1686     MPMLOGSTRING4( "CMPMServer::PublishActiveConnection: Set to: %d, %d, %d",
       
  1687                    iActiveIapId, iActiveSnapId, iActiveBearerType )
       
  1688     }
       
  1689 
       
  1690 // -----------------------------------------------------------------------------
       
  1691 // CMPMServer::NumberOfActiveConnections
       
  1692 // -----------------------------------------------------------------------------
       
  1693 //
       
  1694 TInt CMPMServer::NumberOfActiveConnections()
       
  1695     {
       
  1696     MPMLOGSTRING( "CMPMServer::NumberOfActiveConnections" )
       
  1697     
       
  1698     TInt count( 0 );
       
  1699     
       
  1700     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1701         {
       
  1702         CMPMServerSession* serverSession = GetServerSession(
       
  1703              iActiveBMConns[index].iConnInfo.iConnId );
       
  1704 
       
  1705         if ( iActiveBMConns[index].iConnInfo.iState == EStarted &&
       
  1706              serverSession->ChooseBestIapCalled() )
       
  1707             {
       
  1708             count++;
       
  1709             }
       
  1710         }
       
  1711     
       
  1712     return count;
       
  1713     }
  1420     }
  1714 
  1421 
  1715 // -----------------------------------------------------------------------------
  1422 // -----------------------------------------------------------------------------
  1716 // CMPMServer::UserConnectionInInternet
  1423 // CMPMServer::UserConnectionInInternet
  1717 // -----------------------------------------------------------------------------
  1424 // -----------------------------------------------------------------------------
  2073             }
  1780             }
  2074         }
  1781         }
  2075     stoppedIaps.Close();
  1782     stoppedIaps.Close();
  2076     }
  1783     }
  2077 
  1784 
       
  1785 // ---------------------------------------------------------------------------
       
  1786 // CMPMServer::UpdateOfflineMode
       
  1787 // Offline watcher listens the offline mode and calls this when it's changed.
       
  1788 // ---------------------------------------------------------------------------
       
  1789 //
       
  1790 void CMPMServer::UpdateOfflineMode( TInt aNewModeValue )
       
  1791     {
       
  1792     MPMLOGSTRING2( "CMPMServer::UpdateOfflineMode: Value %d", aNewModeValue )
       
  1793 
       
  1794     iOfflineMode = aNewModeValue;
       
  1795 
       
  1796     if ( iOfflineMode == ECoreAppUIsNetworkConnectionAllowed )
       
  1797         {
       
  1798         // Offline mode finished, reset the QueryResponse variable.
       
  1799         iOfflineWlanQueryResponse = EOfflineResponseUndefined;
       
  1800         }
       
  1801     }
       
  1802 
       
  1803 // ---------------------------------------------------------------------------
       
  1804 // CMPMServer::IsPhoneOffline
       
  1805 // Returns the current offline mode.
       
  1806 // ---------------------------------------------------------------------------
       
  1807 //
       
  1808 TBool CMPMServer::IsPhoneOffline()
       
  1809     {
       
  1810     MPMLOGSTRING( "CMPMServer::IsPhoneOffline" )
       
  1811 
       
  1812     TBool retval = EFalse;
       
  1813     if ( iOfflineMode == ECoreAppUIsNetworkConnectionNotAllowed)
       
  1814         {
       
  1815         retval = ETrue;
       
  1816         MPMLOGSTRING( "CMPMServer::IsPhoneOffline: Yes." )
       
  1817         }
       
  1818     return retval;
       
  1819     }
       
  1820 
       
  1821 // ---------------------------------------------------------------------------
       
  1822 // CMPMServer::OfflineWlanQueryResponse
       
  1823 // Tells the "Use WLAN in offline mode" query's response during the
       
  1824 // current offline mode session.
       
  1825 // ---------------------------------------------------------------------------
       
  1826 //
       
  1827 TOfflineWlanQueryResponse CMPMServer::OfflineWlanQueryResponse()
       
  1828     {
       
  1829     MPMLOGSTRING( "CMPMServer::OfflineWlanQueryResponse" )
       
  1830 
       
  1831 #ifndef _PLATFORM_SIMULATOR_
       
  1832     MPMLOGSTRING2( "CMPMServer::IsOfflineWlanQueryAccepted: %d", iOfflineWlanQueryResponse )
       
  1833     return iOfflineWlanQueryResponse;
       
  1834 #else
       
  1835     // Platsim simulates WLAN and offline-mode. To ease automated testing,
       
  1836     // offline connection confirmation is not asked in Platsim-variant
       
  1837     MPMLOGSTRING( "CMPMServer::OfflineWlanQueryResponse: yes for Platsim" )
       
  1838     return EOfflineResponseYes;
       
  1839 #endif
       
  1840     }
       
  1841 
       
  1842 // ---------------------------------------------------------------------------
       
  1843 // CMPMServer::SetOfflineWlanQueryResponse
       
  1844 // Called when the "Use WLAN in offline mode" note has been responded.
       
  1845 // ---------------------------------------------------------------------------
       
  1846 //
       
  1847 void CMPMServer::SetOfflineWlanQueryResponse( TOfflineWlanQueryResponse aResponse)
       
  1848     {
       
  1849     MPMLOGSTRING( "CMPMServer::SetOfflineWlanQueryResponse" )
       
  1850 
       
  1851     iOfflineWlanQueryResponse = aResponse;
       
  1852     }
       
  1853 
  2078 // -----------------------------------------------------------------------------
  1854 // -----------------------------------------------------------------------------
  2079 // TMPMBlackListConnId::Append
  1855 // TMPMBlackListConnId::Append
  2080 // -----------------------------------------------------------------------------
  1856 // -----------------------------------------------------------------------------
  2081 //
  1857 //
  2082 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )
  1858 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )