fotaapplication/fotaserver/FotaServer/src/FotaNetworkRegStatus.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   GPRS and Wlan status getter for sending Generic Alerts
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 //System Includes
       
    23 #include <startupdomainpskeys.h>	//GlobalRFsStates
       
    24 #include <rconnmon.h>	//RConnectionMonitor
       
    25 #include <featmgr.h>	//Feature Manager
       
    26 #include <features.hrh>	//Feature Manager
       
    27 #include <cmconnectionmethoddef.h>
       
    28 #include <cmmanagerext.h>
       
    29 #include <cmpluginwlandef.h>
       
    30 #include <cmpluginpacketdatadef.h>
       
    31 
       
    32 //User Includes
       
    33 #include "FotaServer.h"
       
    34 #include "FotaNetworkRegStatus.h"
       
    35 
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CFotaNetworkRegStatus::NewL
       
    40 // Symbian 2-Phase construction, NewL used for creating object of this class
       
    41 // This method can leave
       
    42 // -----------------------------------------------------------------------------
       
    43 
       
    44 CFotaNetworkRegStatus* CFotaNetworkRegStatus::NewL(CFotaServer* aObserver)
       
    45 	{
       
    46 	CFotaNetworkRegStatus* self = CFotaNetworkRegStatus::NewLC(aObserver);
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;	
       
    49 	}
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CFotaNetworkRegStatus::NewLC
       
    53 // Symbian 2-Phase construction, NewLC used for creating object of this class
       
    54 // This method can leave
       
    55 // -----------------------------------------------------------------------------
       
    56 
       
    57 CFotaNetworkRegStatus* CFotaNetworkRegStatus::NewLC(CFotaServer* aObserver)
       
    58 	{
       
    59 	CFotaNetworkRegStatus* self = new (ELeave) CFotaNetworkRegStatus (aObserver);
       
    60 	CleanupStack::PushL(self);
       
    61 	self->ConstructL();
       
    62 	
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CFotaNetworkRegStatus::ConstructL
       
    68 // Symbian 2-Phase construction, ConstructL used for constructing the members of this class
       
    69 // This method can leave
       
    70 // -----------------------------------------------------------------------------
       
    71 
       
    72 void CFotaNetworkRegStatus::ConstructL()
       
    73 	{
       
    74 	iTimer.CreateLocal();
       
    75 	iMonitor.ConnectL();
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CFotaNetworkRegStatus::CFotaNetworkRegStatus
       
    80 // C++ Constructor
       
    81 // This method shouldn't leave
       
    82 // -----------------------------------------------------------------------------
       
    83 
       
    84 CFotaNetworkRegStatus::CFotaNetworkRegStatus(CFotaServer* aObserver) : 
       
    85     CActive( CActive::EPriorityStandard ), iObserver(aObserver), iRetriesLeft (KRetries), iGlobalRFState(EFalse)
       
    86     {
       
    87      CActiveScheduler::Add( this ); // Add AO to current active scheduler
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CFotaNetworkRegStatus::~CFotaNetworkRegStatus
       
    92 // C++ Desctructor
       
    93 // This method shouldn't leave
       
    94 // -----------------------------------------------------------------------------
       
    95 
       
    96 CFotaNetworkRegStatus::~CFotaNetworkRegStatus()
       
    97 	{
       
    98 	Cancel();
       
    99 
       
   100 	iTimer.Close();
       
   101 	iMonitor.Close();
       
   102 	}
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CFotaNetworkRegStatus::DoCancel()
       
   106 // Cancels currently active notifier, if such exists
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CFotaNetworkRegStatus::DoCancel()
       
   110 	{
       
   111 	FLOG(_L("CFotaNetworkRegStatus::DoCancel >>"));
       
   112 	
       
   113 	if(IsActive())
       
   114 		{
       
   115 		iTimer.Cancel();
       
   116 //		Cancel();
       
   117 		}
       
   118 		
       
   119 	FLOG(_L("CFotaNetworkRegStatus::DoCancel <<"));
       
   120 	}
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CFotaNetworkRegStatus::StartMonitoringL
       
   124 // Monitors for connection status
       
   125 // This method don't leave
       
   126 // -----------------------------------------------------------------------------
       
   127 
       
   128 void CFotaNetworkRegStatus::StartMonitoringL()
       
   129     {
       
   130     FLOG(_L("CFotaNetworkRegStatus::StartMonitoringL >>"));
       
   131 	
       
   132 	//Check offline state
       
   133 	FLOG(_L("Check GlobalRF state..."));
       
   134 	if (!iGlobalRFState)
       
   135 		{
       
   136 		iGlobalRFState = CheckGlobalRFState();	
       
   137 		}
       
   138 	
       
   139 	if (iGlobalRFState)
       
   140 		{
       
   141 		//Check registration state only if iGlobalRFState is true
       
   142 		FLOG(_L("Check registration state..."));
       
   143 		if (CheckNetworkRegStateL())
       
   144 			{
       
   145 			//If both are successful report complete
       
   146 			FLOG(_L("Network Registration is successful, sending Status as success to FotaServer"));
       
   147 			iObserver->ReportNetworkStatus(ETrue);
       
   148 			return;
       
   149 			}
       
   150 		}
       
   151 	//If one of them is not successful, start timer and retry KRetries times...
       
   152 	
       
   153 	if (--iRetriesLeft>=0)
       
   154 		{
       
   155 		FLOG(_L("Retry count... [%d]"),KRetries-iRetriesLeft);
       
   156 		iTimer.After(iStatus,KTimeInterval); 
       
   157 		if (!IsActive())
       
   158 			SetActive();
       
   159 		}
       
   160 	else
       
   161 		{
       
   162 		FLOG(_L("Maximum retries (%d) reached, sending Status as failure to FotaServer"), KRetries);
       
   163 		iObserver->ReportNetworkStatus(IsWlanSupportedL());		
       
   164 		}
       
   165 
       
   166 	FLOG(_L("CFotaNetworkRegStatus::StartMonitoringL <<"));
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CFotaNetworkRegStatus::RunL()
       
   171 // Called when event accomplished
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CFotaNetworkRegStatus::RunL()
       
   175     {
       
   176     FLOG(_L("CFotaNetworkRegStatus::RunL >>"));
       
   177     
       
   178 	if (iStatus==KErrNone)
       
   179 		{
       
   180 		StartMonitoringL();
       
   181 		}
       
   182 	else
       
   183 		{
       
   184 		iObserver->ReportNetworkStatus(EFalse);	
       
   185 		}
       
   186 
       
   187 	FLOG(_L("CFotaNetworkRegStatus::RunL <<"));
       
   188 	}
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CFotaNetworkRegStatus::RunError
       
   192 // Called when RunL leaves
       
   193 // This method can't leave
       
   194 // -----------------------------------------------------------------------------
       
   195 
       
   196 TInt CFotaNetworkRegStatus::RunError(TInt aError)
       
   197 	{
       
   198 	FLOG(_L("CFotaNetworkRegStatus::RunL >>"));
       
   199 	iObserver->ReportNetworkStatus(EFalse);			
       
   200 	FLOG(_L("CFotaNetworkRegStatus::RunL <<"));
       
   201 	return KErrNone;
       
   202 	}
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CFotaNetworkRegStatus::CheckGlobalRFState
       
   206 // Checks for GlobalRFState, set by Starter
       
   207 // This method can't leave
       
   208 // -----------------------------------------------------------------------------
       
   209 
       
   210 TBool CFotaNetworkRegStatus::CheckGlobalRFState()
       
   211 {
       
   212 	FLOG(_L("CFotaNetworkRegStatus::CheckGlobalRFState >>"));
       
   213 	
       
   214 	RProperty prop;
       
   215 	TInt val = KErrNone;
       
   216 	TInt err = KErrNone;
       
   217 	TInt status = EFalse;
       
   218 	
       
   219 	err = prop.Get(KPSUidStartup, KPSGlobalSystemState, val);
       
   220 	if (err==KErrNone && val==ESwStateNormalRfOn)
       
   221 		{
       
   222 		//Phone is not offline. Check for Network Registration status
       
   223 		FLOG(_L("Phone is online. Check for Network Registration status"));
       
   224 		status = ETrue;
       
   225 		}
       
   226 	else
       
   227 		{
       
   228 		//Phone is offline. No Network activities allowed.
       
   229 		FLOG(_L("Phone is offline. No Network activities allowed."));
       
   230 		status = EFalse;
       
   231 		}
       
   232 	FLOG(_L("CFotaNetworkRegStatus::CheckGlobalRFState, status = %d <<"),status);	
       
   233 	return status;
       
   234 }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CFotaNetworkRegStatus::CheckNetworkRegStatusL
       
   238 // Checks for Network registration status
       
   239 // This method can leave
       
   240 // -----------------------------------------------------------------------------
       
   241 
       
   242 TBool CFotaNetworkRegStatus::CheckNetworkRegStateL()
       
   243 	{
       
   244 	FLOG(_L("CFotaNetworkRegStatus::CheckNetworkRegStateL >>"));
       
   245 	
       
   246 	TBool status = EFalse;
       
   247 	
       
   248 	TInt registrationStatus (KErrNone);
       
   249 	TRequestStatus status1;
       
   250 	iMonitor.GetIntAttribute( EBearerIdGSM,  // See bearer ids from TConnMonBearerId
       
   251 	                         0, 
       
   252 	                         KNetworkRegistration, 
       
   253 	                         registrationStatus, 
       
   254 	                         status1 );
       
   255 	User::WaitForRequest( status1 );
       
   256 
       
   257 	if ( status1.Int() == KErrNone )
       
   258 	    {
       
   259 	    switch (registrationStatus)
       
   260 	    	{
       
   261 	    		case ENetworkRegistrationHomeNetwork:
       
   262 	    		case ENetworkRegistrationRoaming:
       
   263 						{
       
   264 						status = ETrue;
       
   265 						break;	
       
   266 						}
       
   267 				default:
       
   268 						{
       
   269 	    				/* Includes - 	ENetworkRegistrationNotAvailable:
       
   270 	    								ENetworkRegistrationUnknown:
       
   271 	    								ENetworkRegistrationNoService:
       
   272 	    								ENetworkRegistrationEmergencyOnly:
       
   273 	    								ENetworkRegistrationSearching:
       
   274 	    								ENetworkRegistrationBusy:
       
   275 	    								ENetworkRegistrationDenied:*/
       
   276 	    				status = EFalse;
       
   277 	    				break;
       
   278 	    				}
       
   279 	    	}
       
   280 	    }
       
   281 	    
       
   282 	FLOG(_L("CFotaNetworkRegStatus::CheckNetworkRegStateL, status = %d <<"),status);    
       
   283 	return status;
       
   284 	}
       
   285 	
       
   286 // -----------------------------------------------------------------------------
       
   287 // CFotaNetworkRegStatus::IsWlanSupportedL
       
   288 // Checks whether Wlan supported on device and active
       
   289 // This method can leave
       
   290 // -----------------------------------------------------------------------------
       
   291 	
       
   292 TBool CFotaNetworkRegStatus::IsWlanSupportedL()
       
   293 	{
       
   294 	FLOG(_L("CFotaNetworkRegStatus::IsWlanSupportedL >>"));
       
   295 	
       
   296 	TBool status = EFalse;
       
   297 	
       
   298 	FeatureManager::InitializeLibL();
       
   299 	if (FeatureManager::FeatureSupported( KFeatureIdProtocolWlan  )) // check for feature enabled
       
   300 		{
       
   301 		status = ETrue;
       
   302 		}
       
   303 	
       
   304 	FeatureManager::UnInitializeLib();
       
   305 
       
   306 #if defined(__WINS__)
       
   307 	status = ETrue;
       
   308 #endif
       
   309 	
       
   310 	FLOG(_L("CFotaNetworkRegStatus::IsWlanSupportedL, status = %d <<"),status);
       
   311 	return status;
       
   312 	}
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CFotaNetworkRegStatus::IsConnectionPossibleL
       
   316 // Checks whether the network connection is possible in the given IAP Id
       
   317 // This method can leave
       
   318 // -----------------------------------------------------------------------------
       
   319 TBool CFotaNetworkRegStatus::IsConnectionPossibleL(TInt aIapid)
       
   320 	{
       
   321 	FLOG(_L("CFotaNetworkRegStatus::IsConnectionPossibleL >>"));
       
   322 	TBool status (EFalse);
       
   323 	
       
   324 	TUint32 bearer = FindBearerL(aIapid);
       
   325 	if( bearer == KUidPacketDataBearerType )
       
   326 	{
       
   327 	FLOG(_L("Bearer is Packet data"));
       
   328 	if( CheckGlobalRFState() && CheckNetworkRegStateL() )
       
   329 		{
       
   330 		FLOG(_L("Network is up and connection is possible "));
       
   331 		status = ETrue;
       
   332 		}
       
   333 	else
       
   334 		{
       
   335 		FLOG(_L("Network is not up and connection is not possible "));
       
   336 		status = EFalse;
       
   337 		}
       
   338 	}
       
   339 	else if( bearer == KUidWlanBearerType )//for wlan or other bearers
       
   340 		{
       
   341 		FLOG(_L("Bearer is wlan and proceeding for download "));
       
   342 		//proceed & this else loop to be removed
       
   343 		status = ETrue;
       
   344 		}
       
   345 	else
       
   346 		{
       
   347 		FLOG(_L("Bearer is not packet data or WLAN"));
       
   348 		}
       
   349 	
       
   350 	FLOG(_L("CFotaNetworkRegStatus::IsConnectionPossibleL, status = %d <<"),status);
       
   351 	return status;
       
   352 	}
       
   353 
       
   354 
       
   355 // ----------------------------------------------------------------------------------------
       
   356 // CFotaDownload::FindBearerId
       
   357 // Finds the Bearer Id for a given IAP Id
       
   358 // ----------------------------------------------------------------------------------------
       
   359 TUint32 CFotaNetworkRegStatus::FindBearerL(TInt aIapId)
       
   360 	{
       
   361 	FLOG(_L("CFotaNetworkRegStatus::FindBearerL: %d"),aIapId);
       
   362 	TUint32 bearer = 0;
       
   363 	TInt err( KErrNone );
       
   364 	 // Query CM Id
       
   365 	TInt cmId ( aIapId );			        
       
   366 	RCmManagerExt  CmManagerExt;
       
   367 	TRAP( err, CmManagerExt.OpenL() );
       
   368 	FLOG(_L("CmManagerExt.OpenL() with error as  %d"),err);	
       
   369     if( err == KErrNone )
       
   370     	{
       
   371     	RCmConnectionMethodExt cm;
       
   372     	TRAP( err, cm = CmManagerExt.ConnectionMethodL( cmId ) );			        	
       
   373     	FLOG(_L("CmManagerExt.ConnectionMethodL with error as  %d"),err);
       
   374 	    if ( err == KErrNone )
       
   375 	        {	        
       
   376 	        CleanupClosePushL( cm );	  
       
   377 	        FLOG(_L("cm pushed to cleanupstack "));
       
   378 	        bearer = cm.GetIntAttributeL( CMManager::ECmBearerType );	        			        
       
   379 	        FLOG(_L("bearer is %d "),bearer);
       
   380 		    CleanupStack::PopAndDestroy();  // cm	  
       
   381 	        FLOG(_L("cm poped & destroyed from cleanupstack "));
       
   382 	        }	  
       
   383 	    
       
   384 	    CmManagerExt.Close();
       
   385 	    FLOG(_L("CmManagerExt closed "));
       
   386     	}
       
   387     FLOG(_L("CFotaNetworkRegStatus::FindBearerL end with bearer: %d"),bearer);				
       
   388     return bearer;
       
   389 	}
       
   390 
       
   391 // End of File