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