public class PollerConnectivityManager extends ConnectivityManager
NetworkInterface
which address is not 0.0.0.0
.ConnectivityManager.NetworkCallback
Modifier and Type | Field and Description |
---|---|
protected static String |
BASE_PROPERTY
Base property name.
|
protected static NetworkCapabilities |
INTERNET_CONNECTED
Capability with internet access.
|
protected static NetworkCapabilities |
INTERNET_UNCONNECTED
Capability with internet access.
|
Constructor and Description |
---|
PollerConnectivityManager()
Instantiates a
PollerConnectivityManager with default periods and delay and a new timer. |
PollerConnectivityManager(Timer timer)
Instantiates a
PollerConnectivityManager with default value. |
PollerConnectivityManager(Timer timer,
long delay,
long period)
Instantiates a
PollerConnectivityManager with the same period when up or not. |
PollerConnectivityManager(Timer timer,
long delay,
long periodWhenAvailable,
long periodWhenLost)
Instantiates a
PollerConnectivityManager with the different periods when available or not. |
PollerConnectivityManager(Timer timer,
long delay,
long periodWhenAvaialble,
long periodWhenLost,
long periodWhenInternet)
Instantiates a
PollerConnectivityManager with the same period when connected or not. |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the associated timer.
|
protected NetworkCapabilities |
getCapabilities(InetAddress connectedAddress)
Gets the capabilities of a network.
|
protected NetworkInterface |
getNetworkInterface(String name)
Isolate for testing.
|
protected Enumeration<NetworkInterface> |
getNetworkInterfaces()
Isolate for testing.
|
protected void |
log(int msg)
Logs a message.
|
protected void |
log(int msg,
Throwable t)
Logs a message and a throwable.
|
void |
startPolling(long delay)
Starts the polling function.
|
void |
stopPolling()
Stops the polling function.
|
doNotifyAvailabilityChange, doNotifyCapabilitiesChange, getActiveNetwork, getActiveNetworkInfo, getAllNetworks, getNetworkCapabilities, getNetworkInfo, notifyNetworkCallbacks, notifyNetworkCallbacks, registerDefaultNetworkCallback, registerNetworkCallback, setActiveNetwork, setAvailable, unregisterNetworkCallback
protected static final String BASE_PROPERTY
protected static final NetworkCapabilities INTERNET_CONNECTED
protected static final NetworkCapabilities INTERNET_UNCONNECTED
public PollerConnectivityManager()
PollerConnectivityManager
with default periods and delay and a new timer.public PollerConnectivityManager(Timer timer)
PollerConnectivityManager
with default value.timer
- the timer to use, cannot be null
.public PollerConnectivityManager(Timer timer, long delay, long period)
PollerConnectivityManager
with the same period when up or not.timer
- the timer to use, cannot be null
.delay
- the delay before the start.period
- the period for the polling.public PollerConnectivityManager(Timer timer, long delay, long periodWhenAvailable, long periodWhenLost)
PollerConnectivityManager
with the different periods when available or not. The same
period is used wth or without internet access when availble.timer
- the timer to use, cannot be null
.delay
- the delay before the start.periodWhenAvailable
- the period for the polling when at least one interface is available.periodWhenLost
- the period for the polling when all the interface are down.public PollerConnectivityManager(Timer timer, long delay, long periodWhenAvaialble, long periodWhenLost, long periodWhenInternet)
PollerConnectivityManager
with the same period when connected or not.timer
- the timer to use, cannot be null
.delay
- the delay before the start.periodWhenAvaialble
- the period for the polling when at least one interface is available.periodWhenLost
- the period for the polling when all the interface are down.periodWhenInternet
- the period for the polling when there is internet access.public void cancel()
protected NetworkCapabilities getCapabilities(InetAddress connectedAddress)
connectedAddress
- the address to get the capabilities from, cannot be null
.@Nullable protected NetworkInterface getNetworkInterface(String name) throws SocketException
name
- the name of the interface, cannot be null
.SocketException
- if an I/O exception occurs.@Nullable protected Enumeration<NetworkInterface> getNetworkInterfaces() throws SocketException
SocketException
- if an I/O exception occurs.protected void log(int msg)
msg
- the message to log.protected void log(int msg, Throwable t)
msg
- the message to log.t
- a throwable to print, cannot be null
.public void startPolling(long delay)
delay
- the delay before starting.public void stopPolling()