syncmlfw/common/http/src/nsmldialiap.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 23 4af31167ea77
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
    18 #include <CoreApplicationUIsSDKCRKeys.h>
    18 #include <CoreApplicationUIsSDKCRKeys.h>
    19 #include <centralrepository.h>
    19 #include <centralrepository.h>
    20 #include <featmgr.h>   // FeatureManager
    20 #include <featmgr.h>   // FeatureManager
    21 #include <cmdefconnvalues.h>
    21 #include <cmdefconnvalues.h>
    22 #include <cmmanager.h>
    22 #include <cmmanager.h>
    23 #include <cmmanagerkeys.h>
    23 #include <cmpluginwlandef.h>
    24 #include <rconnmon.h>
       
    25 #include <nsmldmconst.h>
       
    26 #include <nsmlconstants.h>
       
    27 #include <etelpckt.h>
    24 #include <etelpckt.h>
    28 #include <etel.h> //for telephone mode
       
    29 #include <etelmm.h> //for telephone mode
       
    30 #include "nsmldialiap.h"
    25 #include "nsmldialiap.h"
    31 #include <nsmlconstants.h>
    26 #include <nsmlconstants.h>
    32 #include "nsmlerror.h"
    27 #include "nsmlerror.h"
    33 
    28 
    34 
    29 
    56 	}
    51 	}
    57 // --------------------------------------------------------------------
    52 // --------------------------------------------------------------------
    58 // CNSmlDialUpAgent::ConstructL()
    53 // CNSmlDialUpAgent::ConstructL()
    59 // 2-phase
    54 // 2-phase
    60 // --------------------------------------------------------------------
    55 // --------------------------------------------------------------------
    61 void CNSmlDialUpAgent::ConstructL(TBool aDmJob)
    56 void CNSmlDialUpAgent::ConstructL()
    62     {
    57     {
    63 	DBG_FILE( _S8("CNSmlDialUpAgent::ConstructL") );
    58 	DBG_FILE( _S8("CNSmlDialUpAgent::ConstructL") );
    64 	CActiveScheduler::Add( this );
    59 	CActiveScheduler::Add( this );
    65 	iCancelCalled = EFalse;    
    60 	iCancelCalled = EFalse;    
    66 	iSocketConnection = EFalse;  
    61 	iSocketConnection = EFalse;    
    67 	iDmjob = aDmJob;
       
    68 	FeatureManager::InitializeLibL();  
    62 	FeatureManager::InitializeLibL();  
    69 	}
    63 	}
    70 //------------------------------------------------------------
    64 //------------------------------------------------------------
    71 // CNSmlDialUpAgent::DoCancel()
    65 // CNSmlDialUpAgent::DoCancel()
    72 // DoCancel() from CActive
    66 // DoCancel() from CActive
   180 	    }
   174 	    }
   181 	    TRequestStatus* status = iEngineStatus;
   175 	    TRequestStatus* status = iEngineStatus;
   182 	    User::RequestComplete( status, iStatus.Int() );			
   176 	    User::RequestComplete( status, iStatus.Int() );			
   183         }
   177         }
   184 	}
   178 	}
   185 
       
   186 // ----------------------------------------------------------------------------
   179 // ----------------------------------------------------------------------------
   187 // CNSmlDialUpAgent::RunError
   180 // CNSmlDialUpAgent::RunError
   188 // ----------------------------------------------------------------------------
   181 // ----------------------------------------------------------------------------
   189 TInt CNSmlDialUpAgent::RunError ( TInt aError )
   182 TInt CNSmlDialUpAgent::RunError ( TInt aError )
   190     {
   183     {
   277     DBG_FILE( _S8("CNSmlDialUpAgent::StartDatacallL") );
   270     DBG_FILE( _S8("CNSmlDialUpAgent::StartDatacallL") );
   278     SetActive();
   271     SetActive();
   279     User::LeaveIfError( iSocketServer.Connect() );		
   272     User::LeaveIfError( iSocketServer.Connect() );		
   280     User::LeaveIfError( iConnection.Open( iSocketServer ) );
   273     User::LeaveIfError( iConnection.Open( iSocketServer ) );
   281     iSocketConnection = ETrue;
   274     iSocketConnection = ETrue;
   282     iConnection.Start( iPrefList, iStatus );
   275     if ( static_cast<TInt32>(iIAPid) == -1 )
       
   276         {
       
   277         iConnection.Start( iPref, iStatus );
       
   278         }
       
   279     else if( static_cast<TInt32>(iIAPid) == -2 ) // default connection 
       
   280         {
       
   281 
       
   282         iConnection.Start( iStatus );	
       
   283 
       
   284         }
       
   285     else
       
   286         {
       
   287         iConnection.Start( iPref, iStatus );
       
   288         }
   283     }
   289     }
   284 	
   290 	
   285 // ---------------------------------------------------------
   291 // ---------------------------------------------------------
   286 // CNSmlDialUpAgent::AttachToConnectionL()
   292 // CNSmlDialUpAgent::AttachToConnectionL()
   287 // Attach to connection allready active 
   293 // Attach to connection allready active 
   378 //  
   384 //  
   379 // ---------------------------------------------------------
   385 // ---------------------------------------------------------
   380 void CNSmlDialUpAgent::DoSettingsL()
   386 void CNSmlDialUpAgent::DoSettingsL()
   381     {
   387     {
   382     DBG_FILE( _S8("CNSmlDialUpAgent::DoSettingsL") );
   388     DBG_FILE( _S8("CNSmlDialUpAgent::DoSettingsL") );
   383     iOffline=IsInOfflineModeL();            
   389     iOffline=IsInOfflineModeL();
   384     iExtPrefs.SetForcedRoaming(EFalse);
   390     if( static_cast<TInt32>(iIAPid) == -1 )
   385     if(  ( static_cast<TInt32>(iIAPid) == -2 ) || 
   391         {		
   386             static_cast<TInt32>(iIAPid) == -1 ) // default connection
   392         if(iOffline)
   387         {
   393             {		
   388         TBool Snap = EFalse;
   394             iPref.SetDialogPreference( ECommDbDialogPrefPrompt );
   389         RCmManager cmmgr;
   395             iPref.SetBearerSet(KUidWlanBearerType);	
   390         cmmgr.OpenL();
       
   391         TCmDefConnValue defConnValue;
       
   392         cmmgr.ReadDefConnL(defConnValue);
       
   393         cmmgr.Close();
       
   394         if(defConnValue.iType == ECmDefConnDestination)
       
   395             {
       
   396             iExtPrefs.SetSnapId(defConnValue.iId);
       
   397             Snap = ETrue;
       
   398             }
   396             }
   399         else if(defConnValue.iType == ECmDefConnConnectionMethod)
   397         else
   400             {
   398             {		
   401             iExtPrefs.SetIapId(defConnValue.iId);   
   399             iPref.SetDialogPreference( ECommDbDialogPrefPrompt );		
   402             }
   400             //iPref.SetBearerSet(EApBearerTypeAllBearers);
   403             iExtPrefs.SetConnSelectionDialog(EFalse);
   401             }				
   404         if(iDmjob)
   402         }
   405             {            
   403     else if( iOffline &&  ( static_cast<TInt32>(iIAPid) == -2 ) ) // default connection
   406             TInt val = KErrNotFound;
   404         {
   407             TInt r2=RProperty::Get(KPSUidNSmlSOSServerKey,KNSmlDMSilentJob,val);
   405         iPref.SetDialogPreference( ECommDbDialogPrefPrompt );
   408 			DBG_FILE_CODE( r2, _S8("CNSmlDialUpAgent::DoSettingsL dc KNSmlDMSilentJob set error code") );
   406         iPref.SetBearerSet(KUidWlanBearerType);	
   409             if(val == ESilent) //silent session
       
   410                 {
       
   411                 //Check the cenrep key
       
   412                 TInt currentmode = KErrNone;
       
   413                 CRepository* rep = CRepository::NewLC( KCRUidCmManager );
       
   414                 rep->Get(KCurrentCellularDataUsage, currentmode );
       
   415                 CleanupStack::PopAndDestroy(); //rep
       
   416                 //if "Always ask", check the roam or home
       
   417                 // if snap dont allow silent connections at all in"always ask"
       
   418                 if(Snap)//Check also for roaming n/w IAP as d.c case
       
   419                     {
       
   420                     //Check the general settings                
       
   421                     if(ECmCellularDataUsageConfirm ==  currentmode)
       
   422                         {
       
   423                         //As silent session fails in roam or home with snap, then dont go for silent sessions .
       
   424                         iExtPrefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourDefault  );
       
   425                         }
       
   426                     else
       
   427                         {
       
   428                         iExtPrefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnSilent );
       
   429                         }
       
   430                     }
       
   431                 else //IAP as d.c
       
   432                     {
       
   433 
       
   434                     //dont set any preference, as this leads to fail  
       
   435                     //else //home n/w or roam n/w with automatic or WLAN only
       
   436                     TBool roaming = EFalse;
       
   437                     IsRoamingL(roaming);
       
   438                     if(ECmCellularDataUsageConfirm ==  currentmode && roaming)
       
   439                         {
       
   440                         //No silent connection preference, as this leads to failure of connection
       
   441                         iExtPrefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourDefault  );
       
   442                         }
       
   443                     else
       
   444                         iExtPrefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnSilent );
       
   445                     }
       
   446                 RProperty::Set(KPSUidNSmlSOSServerKey,KNSmlDMSilentJob,KErrNone);
       
   447                 }
       
   448             }
       
   449         }
   407         }
   450     else
   408     else
   451         {
   409         {
   452         iExtPrefs.SetIapId(iIAPid);
   410         iPref.SetIapId( iIAPid );
   453         iExtPrefs.SetConnSelectionDialog(EFalse);
   411         iPref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
   454         if(iDmjob)
   412         }
   455             {
       
   456             TInt val = KErrNotFound;
       
   457             TInt r2=RProperty::Get(KPSUidNSmlSOSServerKey,KNSmlDMSilentJob,val);
       
   458 			DBG_FILE_CODE( r2, _S8("CNSmlDialUpAgent::DoSettingsL IAP KNSmlDMSilentJob set error code") );
       
   459             if(val == ESilent) //silent session
       
   460                {
       
   461                 //Check the cenrep key
       
   462                 TInt currentmode = KErrNone;
       
   463                 CRepository* rep = CRepository::NewLC( KCRUidCmManager );
       
   464                 rep->Get(KCurrentCellularDataUsage, currentmode );
       
   465                 CleanupStack::PopAndDestroy(); //rep          
       
   466                 TBool roaming = EFalse;
       
   467                 IsRoamingL(roaming);  
       
   468                 if(ECmCellularDataUsageConfirm ==  currentmode && roaming )
       
   469                     {
       
   470                     //As silent session fails in roam or home with snap, then dont go for silent sessions .
       
   471                     iExtPrefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourDefault  );
       
   472                     }
       
   473                 else
       
   474                     {
       
   475                     iExtPrefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnSilent );
       
   476                     }
       
   477                }
       
   478             }
       
   479         RProperty::Set(KPSUidNSmlSOSServerKey,KNSmlDMSilentJob,KErrNone);
       
   480         }
       
   481     iPrefList.AppendL(&iExtPrefs);
       
   482 
       
   483     }
   413     }
   484 //----------------------------------------------------------
   414 //----------------------------------------------------------
   485 //CNsmlDialUpAgent::IsOfflineModeL()
   415 //CNsmlDialUpAgent::IsOfflineModeL()
   486 //------------------------------------------------------------	
       
   487 TBool CNSmlDialUpAgent::IsInOfflineModeL()
   416 TBool CNSmlDialUpAgent::IsInOfflineModeL()
   488     {
   417     {
   489     TInt operationsAllowed( ECoreAppUIsNetworkConnectionAllowed );
   418     TInt operationsAllowed( ECoreAppUIsNetworkConnectionAllowed );
   490 	CRepository* rep = CRepository::NewLC( KCRUidCoreApplicationUIs );
   419 	CRepository* rep = CRepository::NewLC( KCRUidCoreApplicationUIs );
   491 	rep->Get(KCoreAppUIsNetworkConnectionAllowed, operationsAllowed );
   420 	rep->Get(KCoreAppUIsNetworkConnectionAllowed, operationsAllowed );
   492 	CleanupStack::PopAndDestroy(); //rep
   421 	CleanupStack::PopAndDestroy(); //rep
   493 	
   422 	
   494     return ( operationsAllowed == ECoreAppUIsNetworkConnectionNotAllowed ) ? ETrue : EFalse;
   423     return ( operationsAllowed == ECoreAppUIsNetworkConnectionNotAllowed ) ? ETrue : EFalse;
   495     }
   424     }
   496 
       
   497 //------------------------------------------------------------
       
   498 // CNSmlDialUpAgent::IsRoamingL()
       
   499 //  Returns roaming network or not
       
   500 //------------------------------------------------------------	
       
   501 void CNSmlDialUpAgent::IsRoamingL( TBool& aRoaming)
       
   502     {
       
   503      	RTelServer telServer;
       
   504 	User::LeaveIfError( telServer.Connect());
       
   505 	
       
   506 	RTelServer::TPhoneInfo teleinfo;
       
   507 	User::LeaveIfError( telServer.GetPhoneInfo( 0, teleinfo ) );
       
   508 	
       
   509 	RMobilePhone phone;
       
   510 	User::LeaveIfError( phone.Open( telServer, teleinfo.iName ) );
       
   511 	
       
   512 	User::LeaveIfError(phone.Initialise());	
       
   513 	
       
   514 	RMobilePhone::TMobilePhoneNetworkMode mode;        	        	
       
   515 	TInt err = phone.GetCurrentMode( mode );
       
   516 	phone.Close();
       
   517 	telServer.Close();
       
   518 	TInt Bearer = EBearerIdGSM ;
       
   519 	if( KErrNone == err )
       
   520 		{
       
   521 		switch(mode)
       
   522 		{
       
   523 		case RMobilePhone::ENetworkModeGsm:		
       
   524 			{
       
   525 			Bearer = EBearerIdGSM; 			
       
   526 			break;		
       
   527 			}
       
   528 		case RMobilePhone::ENetworkModeWcdma:
       
   529 			{                		     		
       
   530 			Bearer = EBearerIdWCDMA  ;			
       
   531 			}	
       
   532 		default: 
       
   533 			{       			
       
   534 			break;
       
   535 			}        				
       
   536 		}
       
   537 	}	
       
   538     RConnectionMonitor monitor;
       
   539     TRequestStatus status;
       
   540     // open RConnectionMonitor object
       
   541     monitor.ConnectL();
       
   542     CleanupClosePushL( monitor );
       
   543     TInt netwStatus(0);
       
   544     monitor.GetIntAttribute( Bearer, 
       
   545             0, 
       
   546             KNetworkRegistration,
       
   547             netwStatus, 
       
   548             status );
       
   549     User::WaitForRequest( status );
       
   550     CleanupStack::PopAndDestroy(); // Destroying monitor
       
   551     if ( status.Int() == KErrNone && netwStatus == ENetworkRegistrationRoaming )
       
   552         {
       
   553         aRoaming = ETrue;
       
   554         }
       
   555     else //home n/w or some other state in n/w
       
   556         {
       
   557         aRoaming = EFalse;
       
   558         }
       
   559 }