summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/net/MobileDataStateTracker.java67
-rw-r--r--core/java/android/net/NetworkStateTracker.java133
2 files changed, 112 insertions, 88 deletions
diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java
index efbccd2..965af8b 100644
--- a/core/java/android/net/MobileDataStateTracker.java
+++ b/core/java/android/net/MobileDataStateTracker.java
@@ -67,15 +67,10 @@ public class MobileDataStateTracker implements NetworkStateTracker {
/**
* Create a new MobileDataStateTracker
- * @param context the application context of the caller
- * @param target a message handler for getting callbacks about state changes
* @param netType the ConnectivityManager network type
- * @param apnType the Phone apnType
* @param tag the name of this network
*/
- public MobileDataStateTracker(Context context, Handler target, int netType, String tag) {
- mTarget = target;
- mContext = context;
+ public MobileDataStateTracker(int netType, String tag) {
mNetworkInfo = new NetworkInfo(netType,
TelephonyManager.getDefault().getNetworkType(), tag,
TelephonyManager.getDefault().getNetworkTypeName());
@@ -101,6 +96,25 @@ public class MobileDataStateTracker implements NetworkStateTracker {
}
/**
+ * Begin monitoring data connectivity.
+ *
+ * @param context is the current Android context
+ * @param target is the Hander to which to return the events.
+ */
+ public void startMonitoring(Context context, Handler target) {
+ mTarget = target;
+ mContext = context;
+
+ IntentFilter filter =
+ new IntentFilter(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
+ filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
+ filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
+
+ mContext.registerReceiver(new MobileDataStateReceiver(), filter);
+ mMobileDataState = Phone.DataState.DISCONNECTED;
+ }
+
+ /**
* Return the IP addresses of the DNS servers available for the mobile data
* network interface.
* @return a list of DNS addresses, with no holes.
@@ -139,45 +153,6 @@ public class MobileDataStateTracker implements NetworkStateTracker {
public void releaseWakeLock() {
}
- /**
- * Begin monitoring mobile data connectivity.
- */
- public void startMonitoring() {
- IntentFilter filter =
- new IntentFilter(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
- filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
- filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
-
- mContext.registerReceiver(new MobileDataStateReceiver(), filter);
- mMobileDataState = Phone.DataState.DISCONNECTED;
- }
-
- /**
- * Record the roaming status of the device, and if it is a change from the previous
- * status, send a notification to any listeners.
- * @param isRoaming {@code true} if the device is now roaming, {@code false}
- * if it is no longer roaming.
- */
- private void setRoamingStatus(boolean isRoaming) {
- if (isRoaming != mNetworkInfo.isRoaming()) {
- mNetworkInfo.setRoaming(isRoaming);
- Message msg = mTarget.obtainMessage(EVENT_ROAMING_CHANGED, mNetworkInfo);
- msg.sendToTarget();
- }
- }
-
- private void setSubtype(int subtype, String subtypeName) {
- if (mNetworkInfo.isConnected()) {
- int oldSubtype = mNetworkInfo.getSubtype();
- if (subtype != oldSubtype) {
- mNetworkInfo.setSubtype(subtype, subtypeName);
- Message msg = mTarget.obtainMessage(
- EVENT_NETWORK_SUBTYPE_CHANGED, oldSubtype, 0, mNetworkInfo);
- msg.sendToTarget();
- }
- }
- }
-
private class MobileDataStateReceiver extends BroadcastReceiver {
IConnectivityManager mConnectivityManager;
@@ -279,8 +254,6 @@ public class MobileDataStateTracker implements NetworkStateTracker {
setDetailedState(DetailedState.FAILED, reason, apnName);
}
TelephonyManager tm = TelephonyManager.getDefault();
- setRoamingStatus(tm.isNetworkRoaming());
- setSubtype(tm.getNetworkType(), tm.getNetworkTypeName());
}
}
diff --git a/core/java/android/net/NetworkStateTracker.java b/core/java/android/net/NetworkStateTracker.java
index 82735e5..0048a2e 100644
--- a/core/java/android/net/NetworkStateTracker.java
+++ b/core/java/android/net/NetworkStateTracker.java
@@ -16,81 +16,90 @@
package android.net;
+import android.content.Context;
+import android.os.Handler;
+
/**
- * Interface for connectivity service to act on a network interface.
- * All state information for a network should be kept in a Tracker class.
- * This interface defines network-type-independent functions that should
- * be implemented by the Tracker class.
+ * Interface provides the {@link com.android.server.ConnectivityService}
+ * with three services. Events to the ConnectivityService when
+ * changes occur, an API for controlling the network and storage
+ * for network specific information.
+ *
+ * The Connectivity will call startMonitoring before any other
+ * method is called.
*
* {@hide}
*/
public interface NetworkStateTracker {
- public static final int EVENT_STATE_CHANGED = 1;
/**
- * arg1: 1 to show, 0 to hide
- * arg2: ID of the notification
- * obj: Notification (if showing)
+ * -------------------------------------------------------------
+ * Event Interface back to ConnectivityService.
+ *
+ * The events that are to be sent back to the Handler passed
+ * to startMonitoring when the particular event occurs.
+ * -------------------------------------------------------------
*/
- public static final int EVENT_NOTIFICATION_CHANGED = 2;
- public static final int EVENT_CONFIGURATION_CHANGED = 3;
- public static final int EVENT_ROAMING_CHANGED = 4;
- public static final int EVENT_NETWORK_SUBTYPE_CHANGED = 5;
- public static final int EVENT_RESTORE_DEFAULT_NETWORK = 6;
- public static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 7;
/**
- * Fetch NetworkInfo for the network
+ * The network state has changed and the NetworkInfo object
+ * contains the new state.
+ *
+ * msg.what = EVENT_STATE_CHANGED
+ * msg.obj = NetworkInfo object
*/
- public NetworkInfo getNetworkInfo();
+ public static final int EVENT_STATE_CHANGED = 1;
/**
- * Fetch NetworkProperties for the network
+ * msg.what = EVENT_CONFIGURATION_CHANGED
+ * msg.obj = NetworkInfo object
*/
- public NetworkProperties getNetworkProperties();
+ public static final int EVENT_CONFIGURATION_CHANGED = 3;
/**
- * Return the system properties name associated with the tcp buffer sizes
- * for this network.
+ * msg.what = EVENT_RESTORE_DEFAULT_NETWORK
+ * msg.obj = FeatureUser object
*/
- public String getTcpBufferSizesPropName();
+ public static final int EVENT_RESTORE_DEFAULT_NETWORK = 6;
/**
- * Check if private DNS route is set for the network
+ * USED by ConnectivityService only
+ *
+ * msg.what = EVENT_CLEAR_NET_TRANSITION_WAKELOCK
+ * msg.arg1 = mNetTransitionWakeLockSerialNumber
*/
- public boolean isPrivateDnsRouteSet();
-
- /**
- * Set a flag indicating private DNS route is set
- */
- public void privateDnsRouteSet(boolean enabled);
+ public static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 7;
/**
- * Fetch default gateway address for the network
+ * -------------------------------------------------------------
+ * Control Interface
+ * -------------------------------------------------------------
*/
- public int getDefaultGatewayAddr();
-
/**
- * Check if default route is set
+ * Begin monitoring data connectivity.
+ *
+ * This is the first method called when this interface is used.
+ *
+ * @param context is the current Android context
+ * @param target is the Hander to which to return the events.
*/
- public boolean isDefaultRouteSet();
+ public void startMonitoring(Context context, Handler target);
/**
- * Set a flag indicating default route is set for the network
+ * Fetch NetworkInfo for the network
*/
- public void defaultRouteSet(boolean enabled);
+ public NetworkInfo getNetworkInfo();
/**
- * Indicate tear down requested from connectivity
+ * Fetch NetworkProperties for the network
*/
- public void setTeardownRequested(boolean isRequested);
+ public NetworkProperties getNetworkProperties();
/**
- * Check if tear down was requested
+ * Return the system properties name associated with the tcp buffer sizes
+ * for this network.
*/
- public boolean isTeardownRequested();
-
- public void startMonitoring();
+ public String getTcpBufferSizesPropName();
/**
* Disable connectivity to a network
@@ -119,6 +128,11 @@ public interface NetworkStateTracker {
public boolean isAvailable();
/**
+ * Fetch default gateway address for the network
+ */
+ public int getDefaultGatewayAddr();
+
+ /**
* Tells the underlying networking system that the caller wants to
* begin using the named feature. The interpretation of {@code feature}
* is completely up to each networking implementation.
@@ -146,4 +160,41 @@ public interface NetworkStateTracker {
*/
public int stopUsingNetworkFeature(String feature, int callingPid, int callingUid);
+ /**
+ * -------------------------------------------------------------
+ * Storage API used by ConnectivityService for saving
+ * Network specific information.
+ * -------------------------------------------------------------
+ */
+
+ /**
+ * Check if private DNS route is set for the network
+ */
+ public boolean isPrivateDnsRouteSet();
+
+ /**
+ * Set a flag indicating private DNS route is set
+ */
+ public void privateDnsRouteSet(boolean enabled);
+
+ /**
+ * Check if default route is set
+ */
+ public boolean isDefaultRouteSet();
+
+ /**
+ * Set a flag indicating default route is set for the network
+ */
+ public void defaultRouteSet(boolean enabled);
+
+ /**
+ * Check if tear down was requested
+ */
+ public boolean isTeardownRequested();
+
+ /**
+ * Indicate tear down requested from connectivity
+ */
+ public void setTeardownRequested(boolean isRequested);
+
}