bearermanagement/mpm/src/mpmserver.cpp
branchRCL_3
changeset 69 cf1b3ddbe9a1
parent 65 14754bf06654
equal deleted inserted replaced
65:14754bf06654 69:cf1b3ddbe9a1
    45 #include "mpmcsidwatcher.h"
    45 #include "mpmcsidwatcher.h"
    46 #include "mpmdatausagewatcher.h"
    46 #include "mpmdatausagewatcher.h"
    47 #include "mpmpropertydef.h"
    47 #include "mpmpropertydef.h"
    48 #include "mpmofflinewatcher.h"
    48 #include "mpmofflinewatcher.h"
    49 #include "mpmconnpermquerytimer.h"
    49 #include "mpmconnpermquerytimer.h"
    50 #include "mpmofflinequerytimer.h"
       
    51 #include "mpmconnselectiondlgtimer.h"
       
    52 
    50 
    53 // ============================= LOCAL FUNCTIONS ===============================
    51 // ============================= LOCAL FUNCTIONS ===============================
    54 
    52 
    55 // -----------------------------------------------------------------------------
    53 // -----------------------------------------------------------------------------
    56 // PanicServer 
    54 // PanicServer 
   381     iDedicatedClients.Close();
   379     iDedicatedClients.Close();
   382 
   380 
   383     delete iCommsDatAccess;
   381     delete iCommsDatAccess;
   384     
   382     
   385     delete iConnPermQueryTimer;
   383     delete iConnPermQueryTimer;
   386     
       
   387     delete iOfflineQueryTimer; 
       
   388     
       
   389     delete iConnSelectionDlgTimer;
       
   390     }
   384     }
   391 
   385 
   392 
   386 
   393 // -----------------------------------------------------------------------------
   387 // -----------------------------------------------------------------------------
   394 // CMPMServer::NewSessionL
   388 // CMPMServer::NewSessionL
   557                                      CMPMServerSession&  aSession )
   551                                      CMPMServerSession&  aSession )
   558     {
   552     {
   559     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   553     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   560         aConnId )
   554         aConnId )
   561 
   555 
       
   556     TInt count = iActiveBMConns.Count();
       
   557     
       
   558     // Decrement by one, because count is n, 
       
   559     // but indexes in array are 0 .. n-1.
       
   560     // 
       
   561     count--;
       
   562 
   562     // This time we are browsing the array from the end to the beginning, 
   563     // This time we are browsing the array from the end to the beginning, 
   563     // because removing one element from array affects index numbering.
   564     // because removing one element from array affects index numbering.
   564     // Decrement i by one, because count is n, but indexes in array are 0 .. n-1
   565     // 
   565     for ( TInt i = iActiveBMConns.Count() - 1; i >= 0; i-- )
   566     for ( TInt i = count; i >= 0; i-- )
   566         {
   567         {
   567         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   568         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   568             {
   569             {
   569             
       
   570             TInt closeIapId = iActiveBMConns[i].iConnInfo.iIapId;
       
   571             if ( !closeIapId )
       
   572                 {
       
   573                 TRAP_IGNORE( closeIapId = aSession.IapSelectionL()->MpmConnPref().IapId() );
       
   574                 }
       
   575 
       
   576             // If Connection Id found, remove it. 
   570             // If Connection Id found, remove it. 
       
   571             //
   577             iActiveBMConns.Remove( i );
   572             iActiveBMConns.Remove( i );
   578             
   573 
   579             // Update active connection
   574             // Update active connection
   580             if ( aSession.ChooseBestIapCalled() )
   575             if ( aSession.ChooseBestIapCalled() )
   581                 {
   576                 {
   582                 UpdateActiveConnection( aSession );
   577                 UpdateActiveConnection( aSession );
   583                 }
   578                 }
   584             
   579             }
   585             CheckIapForDisconnect( closeIapId );
   580         }
   586             }
   581 
   587         }
       
   588     
       
   589 #ifdef _DEBUG
   582 #ifdef _DEBUG
   590     // Dump array of active connections to log in order to support testing.
   583     // Dump array of active connections to log in order to support testing.
   591     // 
   584     // 
   592     DumpActiveBMConns();
   585     DumpActiveBMConns();
   593 #endif // _DEBUG
   586 #endif // _DEBUG
   602     MPMLOGSTRING2( "CMPMServer::GetBMIap - aConnId = 0x%x", aConnId )
   595     MPMLOGSTRING2( "CMPMServer::GetBMIap - aConnId = 0x%x", aConnId )
   603 
   596 
   604     TUint32 connectionIapId( 0 );
   597     TUint32 connectionIapId( 0 );
   605 
   598 
   606     // Set the Connection Id and SNAP
   599     // Set the Connection Id and SNAP
       
   600     // 
   607     TConnectionInfo connInfo;
   601     TConnectionInfo connInfo;
   608     connInfo.iConnId = aConnId;
   602     connInfo.iConnId = aConnId;
   609 
   603 
   610     TActiveBMConn conn;
   604     TActiveBMConn conn;
   611     conn.iConnInfo = connInfo;
   605     conn.iConnInfo = connInfo;
   613     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   607     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   614 
   608 
   615     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
   609     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
   616         {
   610         {
   617         // If connInfo found, set the Iap Id as connectionIapId
   611         // If connInfo found, set the Iap Id as connectionIapId
       
   612         //
   618         connectionIapId = iActiveBMConns[index1].iConnInfo.iIapId;
   613         connectionIapId = iActiveBMConns[index1].iConnInfo.iIapId;
   619         }
   614         }
   620 
   615 
   621     MPMLOGSTRING2( "CMPMServer::GetBMIap - connectionIapId = %i", 
   616     MPMLOGSTRING2( "CMPMServer::GetBMIap - connectionIapId = %i", 
   622         connectionIapId )
   617         connectionIapId )
   881     {
   876     {
   882     MPMLOGSTRING3(
   877     MPMLOGSTRING3(
   883         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   878         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   884         aIapId, aConnId )
   879         aIapId, aConnId )
   885 
   880 
       
   881     TActiveBMConn conn;
       
   882     conn.iConnInfo.iIapId = aIapId;
       
   883 
   886     // The IAP connection lifetime is determined by the two calls 
   884     // The IAP connection lifetime is determined by the two calls 
   887     // IAPConnectionStarted and IAPConnectionStopped. 
   885     // IAPConnectionStarted and IAPConnectionStopped. 
       
   886     //
       
   887     TInt count = iActiveBMConns.Count();
       
   888 
       
   889     // Decrement by one, because count is n, 
       
   890     // but indexes in array are 0 .. n-1.
       
   891     // 
       
   892     count--;
   888 
   893 
   889     // This time we are browsing the array from the end to the beginning, 
   894     // This time we are browsing the array from the end to the beginning, 
   890     // because removing one element from array affects index numbering.
   895     // because removing one element from array affects index numbering.
   891     // Decrement i by one, because count is n, but indexes in array are 0 .. n-1
   896     // 
   892     for ( TInt i = iActiveBMConns.Count() - 1; i >= 0; i-- )
   897     for ( TInt i = count; i >= 0; i-- )
   893         {
   898         {
   894         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
   899         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
   895             {
   900             {
   896             if ( iActiveBMConns[i].iConnInfo.iSnap == 0 )
   901             if ( iActiveBMConns[i].iConnInfo.iSnap == 0 )
   897                 {
   902                 {
   980             iapInfo.iIap[i].iIapId) 
   985             iapInfo.iIap[i].iIapId) 
   981         }
   986         }
   982 #endif // _DEBUG
   987 #endif // _DEBUG
   983 
   988 
   984     // Read info for forced roaming from Commdat
   989     // Read info for forced roaming from Commdat
   985     TUint32 maxOpenTransAttempts ( KMaxOpenTransAttempts ) ;
   990     TUint32 maxOpenTransAttempts ( KMaxOpenTransAttempts );
   986     TUint32 retryAfter ( KRetryAfter );
   991     TUint32 retryAfter ( KRetryAfter );
   987     TInt err;
   992     TInt err;
   988     // CommDat reading might fail because CommDat session could be locked by another process at the moment
   993     // CommDat reading might fail because CommDat session could be locked by another process at the moment
   989     // So, we may wait/retry to read from CommDat a bit later.
   994     // So, we may wait/retry to read from CommDat a bit later.
   990     TCmUsageOfWlan usageOfWlan ( ECmUsageOfWlanKnown );
   995     TCmUsageOfWlan usageOfWlan ( ECmUsageOfWlanKnown );
  2245 // ---------------------------------------------------------------------------
  2250 // ---------------------------------------------------------------------------
  2246 // CMPMServer::StopCellularConns
  2251 // CMPMServer::StopCellularConns
  2247 // Stop all cellular connections except MMS
  2252 // Stop all cellular connections except MMS
  2248 // ---------------------------------------------------------------------------
  2253 // ---------------------------------------------------------------------------
  2249 //
  2254 //
  2250 void CMPMServer::StopCellularConns( TBool aSilentOnly )
  2255 void CMPMServer::StopCellularConns()
  2251     {
  2256     {
  2252     MPMLOGSTRING( "CMPMServer::StopCellularConns" )
  2257     MPMLOGSTRING( "CMPMServer::StopCellularConns" )
  2253 
  2258 
  2254     TUint32 iapId;
  2259     TUint32 iapId;
  2255 	TMPMBearerType bearerType = EMPMBearerTypeNone;
  2260 	TMPMBearerType bearerType = EMPMBearerTypeNone;
  2274                 err = RProperty::Get( KMPMCathegory, KMPMPropertyKeyMMS, mmsIap );
  2279                 err = RProperty::Get( KMPMCathegory, KMPMPropertyKeyMMS, mmsIap );
  2275                 // Check that it's not MMS IAP.
  2280                 // Check that it's not MMS IAP.
  2276                 if (!(err == KErrNone && iapId == mmsIap))
  2281                 if (!(err == KErrNone && iapId == mmsIap))
  2277                     {
  2282                     {
  2278                     // Stop the conn / IAP.
  2283                     // Stop the conn / IAP.
  2279                     if ( aSilentOnly )
  2284                     StopConnections( iapId );
  2280                         {
       
  2281                         CheckIapForDisconnect( iapId );
       
  2282                         }
       
  2283                     else
       
  2284                         {
       
  2285                         StopConnections( iapId );
       
  2286                         }
       
  2287                     stoppedIaps.Append( iapId );
  2285                     stoppedIaps.Append( iapId );
  2288                     }
  2286                     }
  2289                 }
  2287                 }
  2290             }
  2288             }
  2291         }
  2289         }
  2414         MPMLOGSTRING( "CMPMServer::IsConnPermQueryTimerOn: Yes." )
  2412         MPMLOGSTRING( "CMPMServer::IsConnPermQueryTimerOn: Yes." )
  2415         }
  2413         }
  2416     return retval;
  2414     return retval;
  2417     }
  2415     }
  2418 
  2416 
  2419 // ---------------------------------------------------------------------------
       
  2420 // CMPMServer::StartOfflineQueryTimer
       
  2421 // Starts the offline query timer.
       
  2422 // ---------------------------------------------------------------------------
       
  2423 //
       
  2424 void CMPMServer::StartOfflineQueryTimer()
       
  2425     {
       
  2426     MPMLOGSTRING( "CMPMServer::StartOfflineQueryTimer" )
       
  2427 
       
  2428     if ( !iOfflineQueryTimer )
       
  2429         {
       
  2430         TRAPD( err, iOfflineQueryTimer = CMPMOfflineQueryTimer::NewL( this ) );
       
  2431         if ( err == KErrNone )
       
  2432             {
       
  2433             iOfflineQueryTimer->StartTimer();
       
  2434             MPMLOGSTRING( "CMPMServer::StartOfflineQueryTimer: Ok." )
       
  2435             }
       
  2436         }
       
  2437     }
       
  2438 
       
  2439 // ---------------------------------------------------------------------------
       
  2440 // CMPMServer::ResetOfflineQueryTimer
       
  2441 // Resets the offline query timer.
       
  2442 // ---------------------------------------------------------------------------
       
  2443 //
       
  2444 void CMPMServer::ResetOfflineQueryTimer()
       
  2445     {
       
  2446     MPMLOGSTRING( "CMPMServer::ResetOfflineQueryTimer" )
       
  2447 
       
  2448     if ( iOfflineQueryTimer )
       
  2449         {
       
  2450         delete iOfflineQueryTimer;
       
  2451         iOfflineQueryTimer = NULL;
       
  2452         MPMLOGSTRING( "CMPMServer::ResetOfflineQueryTimer: Ok." )
       
  2453         }
       
  2454     }
       
  2455 
       
  2456 // ---------------------------------------------------------------------------
       
  2457 // CMPMServer::IsOfflineQueryTimerOn
       
  2458 // Tells if the offline query timer is on.
       
  2459 // ---------------------------------------------------------------------------
       
  2460 //
       
  2461 TBool CMPMServer::IsOfflineQueryTimerOn()
       
  2462     {
       
  2463     MPMLOGSTRING( "CMPMServer::IsOfflineQueryTimerOn" )
       
  2464 
       
  2465     TBool retval = EFalse;
       
  2466     if ( iOfflineQueryTimer )
       
  2467         {
       
  2468         retval = ETrue;
       
  2469         MPMLOGSTRING( "CMPMServer::IsOfflineQueryTimerOn: Yes." )
       
  2470         }
       
  2471     return retval;
       
  2472     }
       
  2473 
       
  2474 // ---------------------------------------------------------------------------
       
  2475 // CMPMServer::StartConnSelectionDlgTimer
       
  2476 // Starts the connection selection dialog timer.
       
  2477 // ---------------------------------------------------------------------------
       
  2478 //
       
  2479 void CMPMServer::StartConnSelectionDlgTimer()
       
  2480     {
       
  2481     MPMLOGSTRING( "CMPMServer::StartConnSelectionDlgTimer" )
       
  2482 
       
  2483     if ( !iConnSelectionDlgTimer )
       
  2484         {
       
  2485         TRAPD( err, iConnSelectionDlgTimer = CMPMConnSelectionDlgTimer::NewL( this ) );
       
  2486         if ( err == KErrNone )
       
  2487             {
       
  2488             iConnSelectionDlgTimer->StartTimer();
       
  2489             MPMLOGSTRING( "CMPMServer::StartConnSelectionDlgTimer: Ok." )
       
  2490             }
       
  2491         }
       
  2492     }
       
  2493 
       
  2494 // ---------------------------------------------------------------------------
       
  2495 // CMPMServer::ResetConnSelectionDlgTimer
       
  2496 // Resets the connection selection dialog timer.
       
  2497 // ---------------------------------------------------------------------------
       
  2498 //
       
  2499 void CMPMServer::ResetConnSelectionDlgTimer()
       
  2500     {
       
  2501     MPMLOGSTRING( "CMPMServer::ResetConnSelectionDlgTimer" )
       
  2502 
       
  2503     if ( iConnSelectionDlgTimer )
       
  2504         {
       
  2505         delete iConnSelectionDlgTimer;
       
  2506         iConnSelectionDlgTimer = NULL;
       
  2507         MPMLOGSTRING( "CMPMServer::ResetConnSelectionDlgTimer: Ok." )
       
  2508         }
       
  2509     }
       
  2510 
       
  2511 // ---------------------------------------------------------------------------
       
  2512 // CMPMServer::IsConnSelectionDlgTimerOn
       
  2513 // Tells if the connection selection dialog timer is on.
       
  2514 // ---------------------------------------------------------------------------
       
  2515 //
       
  2516 TBool CMPMServer::IsConnSelectionDlgTimerOn()
       
  2517     {
       
  2518     MPMLOGSTRING( "CMPMServer::IsConnSelectionDlgTimerOn" )
       
  2519 
       
  2520     TBool retval = EFalse;
       
  2521     if ( iConnSelectionDlgTimer )
       
  2522         {
       
  2523         retval = ETrue;
       
  2524         MPMLOGSTRING( "CMPMServer::IsConnSelectionDlgTimerOn: Yes." )
       
  2525         }
       
  2526     return retval;
       
  2527     }
       
  2528     
       
  2529 // -----------------------------------------------------------------------------
       
  2530 // CMPMServer::CheckIapForDisconnect
       
  2531 // -----------------------------------------------------------------------------
       
  2532 //
       
  2533 void CMPMServer::CheckIapForDisconnect( TInt aIapId )
       
  2534     {
       
  2535     MPMLOGSTRING2( "CMPMServer::CheckIapForDisconnect - aIapId = 0x%x", 
       
  2536         aIapId )
       
  2537 
       
  2538     // Fix for case ou1cimx1#468999: stop sessions to cellular iap
       
  2539     // when there is only silent connections to it, and cellular usage is set
       
  2540     // to always ask
       
  2541     
       
  2542     // Check iap type and usage policy
       
  2543     TMPMBearerType bearerType( EMPMBearerTypeNone );
       
  2544     TRAP_IGNORE( bearerType = CommsDatAccess()->GetBearerTypeL( aIapId ) );
       
  2545 
       
  2546     TBool closeIap = ( bearerType == EMPMBearerTypePacketData
       
  2547                 && DataUsageWatcher()->CellularDataUsage() == ECmCellularDataUsageConfirm ); 
       
  2548     
       
  2549     // No need to put iapSessions to CleanupStack; there are no leaves
       
  2550     RPointerArray<CMPMServerSession> iapSessions;
       
  2551     if ( closeIap )
       
  2552         {
       
  2553         // Check for non-silent sessions to iap
       
  2554         // closeIap is left true also when there are no sessions using the iap
       
  2555         for ( TInt i = 0; i < iActiveBMConns.Count(); i++ )
       
  2556             {
       
  2557 
       
  2558             CMPMServerSession* session
       
  2559                 = GetServerSession( iActiveBMConns[i].iConnInfo.iConnId );
       
  2560 
       
  2561             TInt sessionIapId = iActiveBMConns[i].iConnInfo.iIapId;
       
  2562             if ( !sessionIapId )
       
  2563                 {
       
  2564                 TRAP_IGNORE( sessionIapId = session->IapSelectionL()->MpmConnPref().IapId() );
       
  2565                 }
       
  2566 
       
  2567             if ( sessionIapId == aIapId )
       
  2568                 {
       
  2569                 iapSessions.Append( session ); // Don't mind if Append fails
       
  2570                 
       
  2571                 TBool silent( ETrue );
       
  2572                 TRAP_IGNORE( silent = session->IapSelectionL()->MpmConnPref().NoteBehaviour()
       
  2573                                       & TExtendedConnPref::ENoteBehaviourConnDisableNotes );
       
  2574                 if ( !silent )
       
  2575                     {
       
  2576                     // Non-silent session to iap found
       
  2577                     closeIap = EFalse;
       
  2578                     break; // for
       
  2579                     }
       
  2580                 }
       
  2581             }
       
  2582         }
       
  2583     
       
  2584     if ( closeIap )
       
  2585         {
       
  2586         MPMLOGSTRING2( "CMPMServer::CheckIapForDisconnect - stopping silent sessions to iap 0x%x", 
       
  2587             aIapId )
       
  2588         // Stop all (silent) sessions to iap
       
  2589         for ( TInt i = 0; i < iapSessions.Count(); i++)
       
  2590             {
       
  2591             MPMLOGSTRING2( "CMPMServer::CheckIapForDisconnect - stopping connId 0x%x",
       
  2592                     iapSessions[i]->ConnectionId());
       
  2593             iapSessions[i]->StopConnection();
       
  2594             }
       
  2595         }
       
  2596 
       
  2597     iapSessions.Close();
       
  2598     
       
  2599     }
       
  2600 
       
  2601 
       
  2602 // -----------------------------------------------------------------------------
  2417 // -----------------------------------------------------------------------------
  2603 // TMPMBlackListConnId::Append
  2418 // TMPMBlackListConnId::Append
  2604 // -----------------------------------------------------------------------------
  2419 // -----------------------------------------------------------------------------
  2605 //
  2420 //
  2606 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )
  2421 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )