org.fourthline.cling.android
Class AndroidSwitchableRouter

java.lang.Object
  extended by org.fourthline.cling.transport.SwitchableRouterImpl
      extended by org.fourthline.cling.android.AndroidSwitchableRouter
All Implemented Interfaces:
Router, SwitchableRouter

public class AndroidSwitchableRouter
extends SwitchableRouterImpl

Monitors all network connectivity changes, switching the router accordingly.

Author:
Michael Pujos, Christian Bauer

Nested Class Summary
 
Nested classes/interfaces inherited from class org.fourthline.cling.transport.SwitchableRouterImpl
SwitchableRouterImpl.RouterLockAcquisitionException
 
Field Summary
protected  android.content.BroadcastReceiver broadcastReceiver
           
protected  android.net.wifi.WifiManager.MulticastLock multicastLock
           
protected  android.net.NetworkInfo networkInfo
           
protected  android.net.wifi.WifiManager.WifiLock wifiLock
           
 
Fields inherited from class org.fourthline.cling.transport.SwitchableRouterImpl
configuration, protocolFactory, readLock, router, routerLock, writeLock
 
Constructor Summary
AndroidSwitchableRouter(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory, android.content.Context context)
           
 
Method Summary
protected  android.net.wifi.WifiManager.WifiLock createWiFiLock()
           
 boolean disable()
           
 boolean enable()
           
 boolean enableWiFi()
           
protected  int getLockTimeoutMillis()
           
 android.net.NetworkInfo getNetworkInfo()
           
 boolean isEthernet()
           
 boolean isMobile()
           
 boolean isWifi()
           
protected  void onNetworkTypeChange(android.net.NetworkInfo oldNetwork, android.net.NetworkInfo newNetwork)
          Can be overriden by subclasses to do additional work.
protected  void setWifiLock(boolean enable)
           
protected  void setWiFiMulticastLock(boolean enable)
           
 void shutdown()
          Unbinds all sockets and stops all listening threads for datagrams and streams.
 
Methods inherited from class org.fourthline.cling.transport.SwitchableRouterImpl
broadcast, disable, enable, getActiveStreamServers, getConfiguration, getNetworkAddressFactory, getProtocolFactory, handleStartFailure, isEnabled, lock, lock, received, received, send, send, unlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

multicastLock

protected android.net.wifi.WifiManager.MulticastLock multicastLock

wifiLock

protected android.net.wifi.WifiManager.WifiLock wifiLock

networkInfo

protected android.net.NetworkInfo networkInfo

broadcastReceiver

protected android.content.BroadcastReceiver broadcastReceiver
Constructor Detail

AndroidSwitchableRouter

public AndroidSwitchableRouter(UpnpServiceConfiguration configuration,
                               ProtocolFactory protocolFactory,
                               android.content.Context context)
                        throws InitializationException
Throws:
InitializationException
Method Detail

getLockTimeoutMillis

protected int getLockTimeoutMillis()
Overrides:
getLockTimeoutMillis in class SwitchableRouterImpl
Returns:
Defaults to 6 seconds, should be longer than the HTTP client request connection/data read timeouts. Should be longer than it takes the router to be started/shutdown.

shutdown

public void shutdown()
Description copied from interface: Router
Unbinds all sockets and stops all listening threads for datagrams and streams.

Specified by:
shutdown in interface Router
Overrides:
shutdown in class SwitchableRouterImpl

enable

public boolean enable()
               throws SwitchableRouterImpl.RouterLockAcquisitionException
Specified by:
enable in interface SwitchableRouter
Overrides:
enable in class SwitchableRouterImpl
Returns:
true if the router was enabled. false if it's already running.
Throws:
SwitchableRouterImpl.RouterLockAcquisitionException

disable

public boolean disable()
                throws SwitchableRouterImpl.RouterLockAcquisitionException
Specified by:
disable in interface SwitchableRouter
Overrides:
disable in class SwitchableRouterImpl
Returns:
true if the router was disabled. false if it wasn't running.
Throws:
SwitchableRouterImpl.RouterLockAcquisitionException

getNetworkInfo

public android.net.NetworkInfo getNetworkInfo()

isMobile

public boolean isMobile()

isWifi

public boolean isWifi()

isEthernet

public boolean isEthernet()

enableWiFi

public boolean enableWiFi()

setWiFiMulticastLock

protected void setWiFiMulticastLock(boolean enable)

setWifiLock

protected void setWifiLock(boolean enable)

createWiFiLock

protected android.net.wifi.WifiManager.WifiLock createWiFiLock()

onNetworkTypeChange

protected void onNetworkTypeChange(android.net.NetworkInfo oldNetwork,
                                   android.net.NetworkInfo newNetwork)
Can be overriden by subclasses to do additional work.

Parameters:
oldNetwork - null when first called by constructor.


Copyright © 2013 4th Line GmbH, Switzerland. All Rights Reserved.