com.vodafone360.people.service.agent
Class NetworkAgent

java.lang.Object
  extended by com.vodafone360.people.service.agent.NetworkAgent

public class NetworkAgent
extends java.lang.Object

The network Agent monitors the connectivity status of the device and makes decisions about the communication strategy. The Agent has the following states {connected | disconnected}, with changes reported to various listeners in the service.


Nested Class Summary
static class NetworkAgent.AgentDisconnectReason
          Reasons for Service Agent changing state to disconnected
static class NetworkAgent.AgentState
           
private  class NetworkAgent.SettingsContentObserver
          Listens for changes made to People client's status.
static class NetworkAgent.StatesOfService
           
 
Field Summary
private static NetworkAgent.AgentState mAgentState
           
private  boolean mBackgroundData
           
private  BroadcastReceiver mBackgroundDataBroadcastReceiver
          Receive notification from ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED
private  IConnectionManagerInterface mConnectionMgrIf
           
private  ConnectivityManager mConnectivityManager
           
private  ContentResolver mContentResolver
           
private  Context mContext
           
private  boolean mDataRoaming
           
private  NetworkAgent.SettingsContentObserver mDataRoamingSettingObserver
           
private  java.lang.Long mDisableRoamingNotificationUntil
           
private  NetworkAgent.AgentDisconnectReason mDisconnectReason
           
private  boolean mInternetConnected
           
private  BroadcastReceiver mInternetConnectivityReceiver
          Receive notification from ConnectivityManager.CONNECTIVITY_ACTION
private  boolean mIsInBackground
           
private  boolean mIsRoaming
           
private  boolean mNetworkWorking
           
private  BroadcastReceiver mServiceStateRoamingReceiver
          Receive notification from android.intent.action.SERVICE_STATE
private  boolean mWifiActive
           
private  IWorkerThreadControl mWorkerThreadControl
           
static int ROAMING_DIALOG_GLOBAL_OFF
          Roaming notification is off
static int ROAMING_DIALOG_GLOBAL_ON
          Roaming notification is on
private static int TYPE_WIFI
           
 
Constructor Summary
NetworkAgent(Context context, IWorkerThreadControl workerThreadControl, IConnectionManagerInterface connMgrIf)
          The constructor.
 
Method Summary
private  void checkActiveNetworkState()
           
static NetworkAgent.AgentState getAgentState()
           
private  PersistSettings.InternetAvail getInternetAvailSetting()
           
 NetworkAgentState getNetworkAgentState()
           
 boolean getRoamingDeviceSetting()
          Get current device roaming setting.
 int getRoamingNotificationType()
           
 void notifyDataSettingChanged(PersistSettings.InternetAvail val)
          Notify interested parties of changes in Internet setting.
private  void onConnected()
           
private  void onConnectionStateChanged()
          Contains the main logic that determines the agent state for network access
 void onCreate()
          Create NetworkAgent and start observers of device connectivity state.
private  void onDataSettingChanged(java.lang.String settingName)
          Received when user modifies one of the system settings
 void onDestroy()
          Destroy NetworkAgent and un-register observers.
private  void onDisconnected()
           
private  void processRoaming(PersistSettings.InternetAvail val)
          Displaying notification to the user about roaming
static void setAgentState(NetworkAgent.AgentState newState)
          Forces the AgentState to a specific value.
 void setNetworkAgentState(NetworkAgentState state)
           
private  void setNewState(NetworkAgent.AgentState newState)
           
 void setShowRoamingNotificationAgain(boolean showAgain)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROAMING_DIALOG_GLOBAL_ON

public static final int ROAMING_DIALOG_GLOBAL_ON
Roaming notification is on

See Also:
Constant Field Values

ROAMING_DIALOG_GLOBAL_OFF

public static final int ROAMING_DIALOG_GLOBAL_OFF
Roaming notification is off

See Also:
Constant Field Values

TYPE_WIFI

private static final int TYPE_WIFI
See Also:
Constant Field Values

mAgentState

private static NetworkAgent.AgentState mAgentState

mConnectivityManager

private ConnectivityManager mConnectivityManager

mContentResolver

private ContentResolver mContentResolver

mDisconnectReason

private NetworkAgent.AgentDisconnectReason mDisconnectReason

mDataRoamingSettingObserver

private NetworkAgent.SettingsContentObserver mDataRoamingSettingObserver

mInternetConnected

private boolean mInternetConnected

mDataRoaming

private boolean mDataRoaming

mBackgroundData

private boolean mBackgroundData

mIsRoaming

private boolean mIsRoaming

mIsInBackground

private boolean mIsInBackground

mWifiActive

private boolean mWifiActive

mNetworkWorking

private boolean mNetworkWorking

mDisableRoamingNotificationUntil

private java.lang.Long mDisableRoamingNotificationUntil

mWorkerThreadControl

private IWorkerThreadControl mWorkerThreadControl

mConnectionMgrIf

private IConnectionManagerInterface mConnectionMgrIf

mContext

private Context mContext

mBackgroundDataBroadcastReceiver

private final BroadcastReceiver mBackgroundDataBroadcastReceiver
Receive notification from ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED


mInternetConnectivityReceiver

private final BroadcastReceiver mInternetConnectivityReceiver
Receive notification from ConnectivityManager.CONNECTIVITY_ACTION


mServiceStateRoamingReceiver

private final BroadcastReceiver mServiceStateRoamingReceiver
Receive notification from android.intent.action.SERVICE_STATE

Constructor Detail

NetworkAgent

public NetworkAgent(Context context,
                    IWorkerThreadControl workerThreadControl,
                    IConnectionManagerInterface connMgrIf)
The constructor.

Parameters:
context - Android context.
workerThreadControl - Handle to kick the worker thread.
connMgrIf - Handler to signal the connection manager.
Throws:
java.security.InvalidParameterException - Context is NULL.
java.security.InvalidParameterException - IWorkerThreadControl is NULL.
java.security.InvalidParameterException - IConnectionManagerInterface is NULL.
Method Detail

onCreate

public void onCreate()
Create NetworkAgent and start observers of device connectivity state.

Throws:
java.security.InvalidParameterException - DataRoamingSettingObserver is NULL.
java.security.InvalidParameterException - Context is NULL.
java.security.InvalidParameterException - ConnectivityManager is NULL.

onDestroy

public void onDestroy()
Destroy NetworkAgent and un-register observers.

Throws:
java.security.InvalidParameterException - Context is NULL.
java.security.InvalidParameterException - DataRoamingSettingObserver is NULL.

notifyDataSettingChanged

public void notifyDataSettingChanged(PersistSettings.InternetAvail val)
Notify interested parties of changes in Internet setting.

Parameters:
val - updated InternetAvail value.

processRoaming

private void processRoaming(PersistSettings.InternetAvail val)
Displaying notification to the user about roaming

Parameters:
InternetAvail - value.

getInternetAvailSetting

private PersistSettings.InternetAvail getInternetAvailSetting()

getRoamingNotificationType

public int getRoamingNotificationType()

getRoamingDeviceSetting

public boolean getRoamingDeviceSetting()
Get current device roaming setting.

Returns:
current device roaming setting.

setShowRoamingNotificationAgain

public void setShowRoamingNotificationAgain(boolean showAgain)

onDataSettingChanged

private void onDataSettingChanged(java.lang.String settingName)
Received when user modifies one of the system settings


onConnectionStateChanged

private void onConnectionStateChanged()
Contains the main logic that determines the agent state for network access


getAgentState

public static NetworkAgent.AgentState getAgentState()

setNewState

private void setNewState(NetworkAgent.AgentState newState)

onConnected

private void onConnected()

onDisconnected

private void onDisconnected()

checkActiveNetworkState

private void checkActiveNetworkState()

setNetworkAgentState

public void setNetworkAgentState(NetworkAgentState state)

getNetworkAgentState

public NetworkAgentState getNetworkAgentState()

setAgentState

public static void setAgentState(NetworkAgent.AgentState newState)
Forces the AgentState to a specific value.

Parameters:
newState - the state to set Note: to be used only for test purposes


JavaDoc