org.fourthline.cling.android

## Class AndroidRouter

- java.lang.Object
- - org.fourthline.cling.transport.RouterImpl
  - - org.fourthline.cling.android.AndroidRouter

- All Implemented Interfaces:
    Router

      public class AndroidRouter
      extends RouterImpl

  Monitors all network connectivity changes, switching the router accordingly.
  Author:
    Michael Pujos, Christian Bauer

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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.RouterImpl

      `configuration, datagramIOs, enabled, multicastReceivers, networkAddressFactory, protocolFactory, readLock, routerLock, streamClient, streamServers, writeLock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AndroidRouter(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory, android.content.Context context)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected android.content.BroadcastReceiver` | `createConnectivityBroadcastReceiver()`
    `boolean` | `disable()` Unbinds all sockets and stops all listening threads for datagrams and streams.
    `boolean` | `enable()` Initializes listening services: First an instance of `MulticastReceiver` is bound to each network interface.
    `boolean` | `enableWiFi()`
    `protected int` | `getLockTimeoutMillis()`
    `android.net.NetworkInfo` | `getNetworkInfo()`
    `protected void` | `handleRouterExceptionOnNetworkTypeChange(RouterException ex)` Handles errors when network has been switched, during reception of network switch broadcast.
    `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()` Disables the router and releases all other resources.
    `void` | `unregisterBroadcastReceiver()`

    - ### Methods inherited from class org.fourthline.cling.transport.RouterImpl

      `broadcast, disable, enable, getActiveStreamServers, getConfiguration, getProtocolFactory, handleStartFailure, isEnabled, lock, lock, received, received, send, send, startAddressBasedTransports, startInterfaceBasedTransports, 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

    - #### AndroidRouter

          public AndroidRouter(UpnpServiceConfiguration configuration,
                               ProtocolFactory protocolFactory,
                               android.content.Context context)
                        throws InitializationException

      Throws:
        `InitializationException`

  - ### Method Detail

    - #### createConnectivityBroadcastReceiver

          protected android.content.BroadcastReceiver createConnectivityBroadcastReceiver()

    - #### getLockTimeoutMillis

          protected int getLockTimeoutMillis()

      Overrides:
        `getLockTimeoutMillis` in class `RouterImpl`
      Returns:
        Defaults to 6 seconds, should be longer than it takes the router to be enabled/disabled.

    - #### shutdown

          public void shutdown()
                        throws RouterException

      Description copied from interface: `Router`
      Disables the router and releases all other resources.
      Specified by:
        `shutdown` in interface `Router`
      Overrides:
        `shutdown` in class `RouterImpl`
      Throws:
        `RouterException`

    - #### enable

          public boolean enable()
                         throws RouterException

      Description copied from class: `RouterImpl`
      Initializes listening services: First an instance of `MulticastReceiver` is bound to each network interface. Then an instance of `DatagramIO` and `StreamServer` is bound to each bind address returned by the network address factory, respectively. There is only one instance of `StreamClient` created and managed by this router.
      Specified by:
        `enable` in interface `Router`
      Overrides:
        `enable` in class `RouterImpl`
      Returns:
        `true` if the router was enabled. `false` if it's already running.
      Throws:
        `RouterException`

    - #### disable

          public boolean disable()
                          throws RouterException

      Description copied from interface: `Router`
      Unbinds all sockets and stops all listening threads for datagrams and streams.
      Specified by:
        `disable` in interface `Router`
      Overrides:
        `disable` in class `RouterImpl`
      Returns:
        `true` if the router was disabled. `false` if it wasn't running.
      Throws:
        `RouterException`

    - #### getNetworkInfo

          public android.net.NetworkInfo getNetworkInfo()

    - #### isMobile

          public boolean isMobile()

    - #### isWifi

          public boolean isWifi()

    - #### isEthernet

          public boolean isEthernet()

    - #### enableWiFi

          public boolean enableWiFi()

    - #### unregisterBroadcastReceiver

          public void unregisterBroadcastReceiver()

    - #### setWiFiMulticastLock

          protected void setWiFiMulticastLock(boolean enable)

    - #### setWifiLock

          protected void setWifiLock(boolean enable)

    - #### onNetworkTypeChange

          protected void onNetworkTypeChange(android.net.NetworkInfo oldNetwork,
                                             android.net.NetworkInfo newNetwork)
                                      throws RouterException

      Can be overriden by subclasses to do additional work.
      Parameters:
        `oldNetwork` - `null` when first called by constructor.
      Throws:
        `RouterException`

    - #### handleRouterExceptionOnNetworkTypeChange

          protected void handleRouterExceptionOnNetworkTypeChange(RouterException ex)

      Handles errors when network has been switched, during reception of network switch broadcast. Logs a warning by default, override to change this behavior.

Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.