bearermanagement/mpm/src/mpmiapselection.cpp
branchRCL_3
changeset 58 83ca720e2b9a
parent 57 05bc53fe583b
child 62 bb1f80fb7db2
--- a/bearermanagement/mpm/src/mpmiapselection.cpp	Tue Aug 31 15:35:44 2010 +0300
+++ b/bearermanagement/mpm/src/mpmiapselection.cpp	Wed Sep 01 12:23:51 2010 +0100
@@ -17,10 +17,13 @@
 
 #include "mpmiapselection.h"
 #include "mpmlogger.h"
+#include "mpmdialog.h"
 #include "mpmserversession.h"
 #include "mpmcommsdataccess.h"
 #include "mpmconnmonevents.h"
 #include "mpmconfirmdlgstarting.h"
+#include "mpmdefaultconnection.h"
+#include "mpmwlanquerydialog.h"
 #include "extendedconnpref.h"
 
 // ---------------------------------------------------------------------------
@@ -28,14 +31,14 @@
 // ---------------------------------------------------------------------------
 //
 CMPMIapSelection::CMPMIapSelection( CMPMCommsDatAccess*  aCommsDatAccess,
-                                    CMPMServerSession*   aSession,
-                                    CConnectionUiUtilities* aConnUiUtils )
+                                    CMPMServerSession*   aSession )
     : iChooseIapState( ENoConnection ),
       iCommsDatAccess( aCommsDatAccess ),
-      iConnUiUtils( aConnUiUtils ),
       iStoredIapInfo(),
       iSession( aSession ),
       iConfirmDlgStarting( NULL ),
+      iDialog( NULL ),
+      iWlanDialog( NULL ),
       iNextBestExists( EFalse ),
       iUserSelectionIapId( 0 ),
       iUserSelectionSnapId( 0 ),
@@ -59,12 +62,10 @@
 // ---------------------------------------------------------------------------
 //
 CMPMIapSelection* CMPMIapSelection::NewL( CMPMCommsDatAccess*  aCommsDatAccess,
-                                          CMPMServerSession*   aSession,
-                                          CConnectionUiUtilities* aConnUiUtils )
+                                          CMPMServerSession*   aSession )
     {
     CMPMIapSelection* self = new ( ELeave ) CMPMIapSelection( aCommsDatAccess,
-                                                              aSession,
-                                                              aConnUiUtils );
+                                                              aSession );
     CleanupStack::PushL( self );
     self->ConstructL();
     CleanupStack::Pop( self );
@@ -83,6 +84,8 @@
     StopDisplayingStartingDlg();
     
     delete iConfirmDlgStarting;
+    delete iDialog;
+    delete iWlanDialog;
     }
 
 // -----------------------------------------------------------------------------
@@ -163,8 +166,7 @@
             return;
             }
         }
-        
-           
+    
     if  ( iChooseIapPref.ConnSelectionDialog() )
         {
         // Complete selection with error code if wlan only was set and bearer set as cellular 
@@ -184,7 +186,7 @@
         // Default connection is requested.
 
         MPMLOGSTRING( "CMPMIapSelection::ChooseIapL:\
-            Default Connection" )
+ Default Connection" )
 
         if ( iSession->UseUserConnPref() )
             {
@@ -200,17 +202,39 @@
             return;
             }
 
-        // Read the default connection values
         TCmDefConnType type( TCmDefConnType( 0 ) );
         TUint32 id( 0 );
-        iCommsDatAccess->GetDefaultConnectionL( type, id );
+        iSession->MyServer().DefaultConnection()->GetDefaultConnectionL( type, id );
         
         MPMLOGSTRING3( "CMPMIapSelection::ChooseIapL:\
-            default connection type %d id %d", type, id )
-        
-        // set the received snap id and open the connection
-        iChooseIapPref.SetSnapId( id );
-        ExplicitConnectionL();
+ default connection type %d id %d", type, id )
+       
+        if( type == ECmDefConnConnectionMethod )
+            {
+            iChooseIapPref.SetIapId( id );
+            iChooseIapPref.SetSnapId( 0 );
+            ExplicitConnectionL();
+            }
+        else if( type == ECmDefConnDestination )
+            { 
+            iChooseIapPref.SetSnapId( id );
+            ExplicitConnectionL();
+            }
+        else
+            {
+            if( iCommsDatAccess->IsSnapEmptyL( id ) )
+                {
+                // start implicit connection
+                ImplicitConnectionL();
+                return;
+                }
+
+            iChooseIapPref.SetSnapId( id );
+
+            // start connection as if explicitly defined 
+            // by application
+            ExplicitConnectionL();
+            }       
         }
     else if ( iChooseIapPref.ConnType() == TMpmConnPref::EConnTypeExplicit )
         {
@@ -327,8 +351,13 @@
         iChooseIapPref.SetIapId( validateIapId );
         iChooseIapPref.SetNetId( retNetId );
 
-        if ( !iapTypeLanOrWlan &&                  
-             iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMRoamingStatusUnknown )
+        // In case offline mode is enabled, only LAN or WLAN is allowed.
+        // If some other bearer has been requested, then error code 
+        // KErrGprsOfflineMode should be returned instead of KErrNone.
+        // 
+        
+        if ( !iapTypeLanOrWlan && ( iSession->MyServer().IsPhoneOffline() ||                 
+             iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMRoamingStatusUnknown ) )
             {
             ChooseIapComplete( KErrGprsOfflineMode, &iChooseIapPref );
             }
@@ -337,13 +366,9 @@
             TWlanIapType wlanType = iCommsDatAccess->CheckWlanL( validateIapId );
             if( wlanType != ENotWlanIap )
                 {
-                // Add info into the BM connections
-                iSession->MyServer().AppendBMConnection( iSession->ConnectionId(), 
-                                    iChooseIapPref.SnapId(),
-                                    validateIapId,
-                                    EStarting,
-                                    *iSession );
-                ChooseIapComplete( KErrNone, &iChooseIapPref );
+                iChooseIapState = EExplicitConnection;
+                iWlanDialog = CMPMWlanQueryDialog::NewL( *this, validateIapId );
+                iWlanDialog->StartWlanQueryL();
                 return;                
                 }
 
@@ -353,39 +378,36 @@
             if ( iSession->IsConfirmFirstL( validateIapId ) &&
                  !( iSession->MyServer().CommsDatAccess()->IsVirtualIapL( validateIapId ) ))
                 {
-                // Check that queries aren't disabled and
-                // enough time has elapsed from the last query cancelled by the user.
-                if ( !( iChooseIapPref.NoteBehaviour()
-                        & TExtendedConnPref::ENoteBehaviourConnDisableQueries ) &&
-                     !iSession->MyServer().IsConnPermQueryTimerOn() )
+                // Check if we are roaming and cellular data usage query has not yet been presented
+                // to the user in this country
+                if ( iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMInternationalRoaming )
                     {
-                    TConnectionId connId = iSession->ConnectionId();
-
-                    // Set confirmation type based on roaming status
-                    CMPMConfirmDlg::TDialogType type = 
-                            CMPMConfirmDlg::EConfirmDlgHomeNetwork;
-                    if ( iSession->MyServer().RoamingWatcher()->RoamingStatus()
-                            == EMPMInternationalRoaming ) {
-                        type = CMPMConfirmDlg::EConfirmDlgVisitorNetwork;
-                    }
-                    
-                    iConfirmDlgStarting = CMPMConfirmDlgStarting::NewL( 
-                        *this, 
-                        connId,
-                        snap, 
-                        validateIapId, 
-                        type,
-                        iChooseIapPref,
-                        iSession->MyServer(),
-                        *iSession,
-                        EExplicitConnection );
-                    return;    
-                    }
-                else
-                    {
-                    // Queries disabled, connection must fail
-                    ChooseIapComplete( KErrPermissionDenied, &iChooseIapPref );
-                    return;
+                    // Check that queries aren't disabled and
+                    // enough time has elapsed from the last query cancelled by the user.
+                    if ( !( iChooseIapPref.NoteBehaviour() & TExtendedConnPref::ENoteBehaviourConnDisableQueries ) &&
+                            !iSession->MyServer().IsConnPermQueryTimerOn() )
+                        {
+                        TConnectionId connId = iSession->ConnectionId();
+                                                            
+                        // International roaming
+                        iConfirmDlgStarting = CMPMConfirmDlgStarting::NewL( 
+                            *this, 
+                            connId,
+                            snap, 
+                            validateIapId, 
+                            CMPMConfirmDlg::EConfirmDlgVisitorNetwork,
+                            iChooseIapPref,
+                            iSession->MyServer(),
+                            *iSession,
+                            EExplicitConnection );
+                        return;    
+                        }
+                    else
+                        {
+                        // Queries disabled, connection must fail
+                        ChooseIapComplete( KErrPermissionDenied, &iChooseIapPref );
+                        return;
+                        }
                     }
                 }
                            
@@ -440,6 +462,19 @@
     }
 
 // -----------------------------------------------------------------------------
+// CMPMIapSelection::UpdateConnectionDialog
+// -----------------------------------------------------------------------------
+//
+void CMPMIapSelection::UpdateConnectionDialogL()
+    {
+    if( iDialog )
+        {
+        MPMLOGSTRING( "CMPMIapSelection::UpdateConnectionDialogL data will be updated" )
+        iDialog->PublishSortSnapInfoL();
+        }
+    }
+
+// -----------------------------------------------------------------------------
 // CMPMIapSelection::CompleteExplicitSnapConnectionL
 // -----------------------------------------------------------------------------
 //
@@ -463,17 +498,7 @@
     // Check if any suitable IAP's were found, if not then complete selection with error code
     if ( validateIapId == 0 )
         {
-        if ( !( iChooseIapPref.NoteBehaviour() & TExtendedConnPref::ENoteBehaviourConnDisableQueries ) &&
-                ( iChooseIapPref.ConnType() == TMpmConnPref::EConnTypeDefault ||
-                ( iChooseIapPref.ConnType() == TMpmConnPref::EConnTypeExplicit &&
-                  iCommsDatAccess->IsInternetSnapL( 0, snap ) ) ) )
-            {
-            ImplicitConnectionL();
-            }
-        else
-            {
-            ChooseIapComplete( KErrNotFound, NULL );
-            }
+        ChooseIapComplete( KErrNotFound, NULL );
         CleanupStack::PopAndDestroy( &availableIAPList );
         return;
         }
@@ -495,8 +520,8 @@
         {
         ChooseIapComplete( KErrGprsServicesNotAllowed, NULL );
         }
-    else if ( !iapTypeLanOrWlan &&                 
-               iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMRoamingStatusUnknown )
+    else if ( !iapTypeLanOrWlan && ( iSession->MyServer().IsPhoneOffline() ||                 
+               iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMRoamingStatusUnknown ) )
         {
         // In case offline mode is enabled, only LAN or WLAN is allowed.
         // If some other bearer has been requested, then error code 
@@ -515,7 +540,7 @@
             // Check that queries aren't disabled and
             // enough time has elapsed from the last query cancelled by the user.
             if ( !( iChooseIapPref.NoteBehaviour() & TExtendedConnPref::ENoteBehaviourConnDisableQueries ) &&
-                 !iSession->MyServer().IsConnPermQueryTimerOn() )
+                    !iSession->MyServer().IsConnPermQueryTimerOn() )
                 {
                 if ( iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMInternationalRoaming )
                     {
@@ -555,14 +580,19 @@
             }
         else
             {
-            // Add info into the BM connections
-            //
-            iSession->MyServer().AppendBMConnection( connId, 
+            if ( !StartWlanQueryIfNeededL( validateIapId ) )
+                {
+                // Add info into the BM connections
+                //
+                iSession->MyServer().AppendBMConnection( connId, 
                         snap, 
                         validateIapId, 
                         EStarting,
                         *iSession );
-            ChooseIapComplete( KErrNone, &iChooseIapPref );
+                ChooseIapComplete( KErrNone, &iChooseIapPref );
+
+                }
+
             }
         }
 
@@ -601,18 +631,26 @@
     }
 
 // -----------------------------------------------------------------------------
-// CMPMIapSelection::IsIapWlanL
+// CMPMIapSelection::StartWlanQueryIfNeededL
 // -----------------------------------------------------------------------------
 //
-TBool CMPMIapSelection::IsIapWlanL( TUint32 aIapId )
+TBool CMPMIapSelection::StartWlanQueryIfNeededL( TUint32 aIapId, TBool aIsRoaming )
     {
-    MPMLOGSTRING2( "CMPMIapSelection::StartWlanQueryIfNeededL iap %d, ", aIapId)
+    MPMLOGSTRING3( "CMPMIapSelection::StartWlanQueryIfNeededL iap %d, isRoaming %d ", 
+                   aIapId,
+                   aIsRoaming )
+    TBool wlanQueryNeeded( EFalse );
+    // If wlan iap check if offline note needed
     TWlanIapType wlanType = iCommsDatAccess->CheckWlanL( aIapId );
-    if( wlanType != EWlanIap )
+    if( wlanType != ENotWlanIap )
         {
-        return EFalse;
+        iIsRoaming = aIsRoaming;
+        iChooseIapState = EExplicitConnection;
+        iWlanDialog = CMPMWlanQueryDialog::NewL( *this, aIapId );
+        iWlanDialog->StartWlanQueryL();
+        wlanQueryNeeded = ETrue;
         }
-    return ETrue;
+    return wlanQueryNeeded;
     }
 
 // -----------------------------------------------------------------------------
@@ -621,6 +659,8 @@
 //
 void CMPMIapSelection::ImplicitConnectionCheckWlanScanNeededL()
     {
+    __ASSERT_DEBUG( !iDialog, PanicServer( EMPMReceiveAlreadyActive ) );
+
     MPMLOGSTRING( "CMPMIapSelection::ImplicitConnectionCheckWlanScanNeededL" )
 
     iCommsDatAccess->CheckWLANIapL( *iSession );
@@ -689,6 +729,33 @@
     const TMpmConnPref* aPolicyPref )
     {
     MPMLOGSTRING2( "CMPMIapSelection::ChooseIapComplete aError = %d", aError )
+    
+    if ( ( aError == KErrNone ) &&
+        !( iChooseIapPref.NoteBehaviour() &
+           TExtendedConnPref::ENoteBehaviourConnDisableNotes ) )
+        {
+        TConnectionState state =
+            iSession->MyServer().CheckUsageOfIap( aPolicyPref->IapId(), 
+                                                  iSession->ConnectionId() );
+        TBool connectionAlreadyActive = (state == EStarted || state == EStarting || state == ERoaming);
+        if ( !connectionAlreadyActive &&
+                ( iSession->IsMMSIap( aPolicyPref->IapId() ) == EFalse ) )
+            {
+            CConnectionUiUtilities* connUiUtils( NULL );
+            TRAPD( popupError, connUiUtils = CConnectionUiUtilities::NewL() );
+            if ( popupError == KErrNone )
+        	    {
+            	connUiUtils->ConnectingViaDiscreetPopup( aPolicyPref->IapId() );
+               	delete connUiUtils;
+        	    }
+            }
+        }
+    
+    if( iWlanDialog )
+        {
+        delete iWlanDialog;
+        iWlanDialog = NULL;
+        }
 
     iSession->ChooseIapComplete( aError, aPolicyPref );
     // Set choose iap state to none
@@ -699,6 +766,63 @@
     iImplicitState = EImplicitStart;
     }
 
+
+// -----------------------------------------------------------------------------
+// CMPMIapSelection::UserWlanSelectionDoneL
+// -----------------------------------------------------------------------------
+//
+void CMPMIapSelection::UserWlanSelectionDoneL( TInt aError, TUint32 aIapId )
+    {
+    MPMLOGSTRING( "CMPMIapSelection::UserWlanSelectionDoneL" )
+
+    if( iIsRoaming )
+        {
+        iIsRoaming = EFalse;
+        iSession->MigrateCallbackL( aError );
+        delete iWlanDialog;
+        iWlanDialog = NULL;
+        }
+    else
+        {
+        if( aError != KErrNone )
+            {
+            MPMLOGSTRING2( "CMPMIapSelection::UserWlanSelectionDoneL - Error = %d, completing", aError ) 
+            ChooseIapComplete( aError, NULL );        
+            }
+        else
+            {
+            if( iChooseIapState == EImplicitConnection )
+                {
+                iUserSelectionIapId = aIapId;
+                ImplicitConnectionL();    
+                }
+            else if( iChooseIapState == EExplicitConnection )
+                {
+                MPMLOGSTRING( "CMPMIapSelection::UserWlanSelectionDoneL completing explicit iap connection" ) 
+                iChooseIapPref.SetIapId( aIapId );
+                // Add info into the BM connections
+                //
+                iSession->MyServer().AppendBMConnection( iSession->ConnectionId(), 
+                                                         iChooseIapPref.SnapId(),
+                                                         aIapId,
+                                                         EStarting,
+                                                         *iSession );
+                iWlanDialog->StoreEasyWlanSelectionL();
+                delete iWlanDialog;
+                iWlanDialog = NULL;
+
+                ChooseIapComplete( KErrNone, &iChooseIapPref );
+                }
+            else
+                {
+                MPMLOGSTRING( "CMPMIapSelection::UserWlanSelectionDoneL - error, no connection state" ) 
+                }
+            
+            }
+        
+        }
+    }
+
 // -----------------------------------------------------------------------------
 // CMPMIapSelection::HandleUserSelectionError
 // -----------------------------------------------------------------------------
@@ -709,6 +833,8 @@
         aError )
     
     ChooseIapComplete( aError, NULL );
+    delete iDialog;
+    iDialog = NULL;
     }
 
        
@@ -732,7 +858,7 @@
         // User selected SNAP
         // 
         TMpmConnPref userPref;
-        iUserSelectionSnapId = aId;
+        iUserSelectionSnapId = iCommsDatAccess->MapNetIdtoSnapAPL( aId );
         userPref.SetSnapId( iUserSelectionSnapId );
         userPref.SetIapId( 0 );
 
@@ -757,7 +883,12 @@
 
         }
     
-    // Letting a function leave here would panic the whole MPM.
+    // We are done
+    // 
+    delete iDialog;
+    iDialog = NULL;
+    
+    // Dialog is deleted. Letting a function leave here would panic the whole MPM.
     //
     TRAPD( err, ImplicitConnectionL() );
     if( err != KErrNone )
@@ -775,10 +906,15 @@
     MPMLOGSTRING( "CMPMIapSelection::ImplicitConnectionWlanNoteL" )
     
     TWlanIapType wlanType = iCommsDatAccess->CheckWlanL( iUserSelectionIapId );
-
+    // In case offline mode is enabled, only LAN or WLAN is allowed.
+    // If some other bearer has been requested, then error code 
+    // KErrGprsOfflineMode should be returned instead of KErrNone.
+    // 
     if( wlanType != ENotWlanIap )
         {
-        ImplicitConnectionL();
+        iChooseIapState = EImplicitConnection;
+        iWlanDialog = CMPMWlanQueryDialog::NewL( *this, iUserSelectionIapId );
+        iWlanDialog->StartWlanQueryL();
         return;                
         }
     else
@@ -796,7 +932,7 @@
                 // Check that queries aren't disabled and
                 // enough time has elapsed from the last query cancelled by the user.
                 if ( !( iChooseIapPref.NoteBehaviour() & TExtendedConnPref::ENoteBehaviourConnDisableQueries ) &&
-                     !iSession->MyServer().IsConnPermQueryTimerOn() )
+                        !iSession->MyServer().IsConnPermQueryTimerOn() )
                     {
                     TConnectionId connId = iSession->ConnectionId();
                                                                     
@@ -841,8 +977,8 @@
                                    iapTypeLanOrWlan,
                                    *iSession );
                                    
-    if ( !iapTypeLanOrWlan &&            
-            iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMRoamingStatusUnknown )
+    if ( !iapTypeLanOrWlan && ( iSession->MyServer().IsPhoneOffline() ||            
+            iSession->MyServer().RoamingWatcher()->RoamingStatus() == EMPMRoamingStatusUnknown ) )
         {
         MPMLOGSTRING2( "CMPMIapSelection::CompleteImplicitConnectionL: Completing with code = %i",
                 KErrGprsOfflineMode )
@@ -864,6 +1000,14 @@
         iChooseIapPref.SetIapId( iUserSelectionIapId );
         iChooseIapPref.SetNetId( retNetId );
             
+        
+        if( iWlanDialog )
+            {
+            iWlanDialog->StoreEasyWlanSelectionL();
+            delete iWlanDialog;
+            iWlanDialog = NULL;
+            }
+        
         ChooseIapComplete( KErrNone, &iChooseIapPref );
         }
     
@@ -878,14 +1022,13 @@
     MPMLOGSTRING( "CMPMIapSelection::ImplicitConnectionIapSelectionL" )
     iSession->AvailableUnblacklistedIapsL( iStoredAvailableIaps, iSession->ConnectionId() );
 
-    // The connection selection dialog doesn't exist any longer, thus
-    // the HandleUserSelection is called with the Internet SNAP that is returned instead
-    TInt err = KErrNone;
-    TInt internetSnapId = 0;
-    // if the reading leaves, then the internet snap did not exist for some reason
-    TRAP ( err, internetSnapId = 
-        iCommsDatAccess->DestinationIdL( CMManager::ESnapPurposeInternet ));
-    HandleUserSelectionL( false, internetSnapId, err );
+    // Create and initiate user dialog
+    //
+    iDialog = CMPMDialog::NewL( *this,
+                                iStoredAvailableIaps,
+                                iChooseIapPref.BearerSet(),
+                                *iSession->MyServer().ConnectDialogQueue(),
+                                iSession->MyServer() );
     }
 
 // -----------------------------------------------------------------------------