summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/net/MobileDataStateTracker.java67
-rw-r--r--core/java/android/net/NetworkStateTracker.java133
-rw-r--r--services/java/com/android/server/ConnectivityService.java35
-rw-r--r--services/java/com/android/server/WifiService.java24
-rw-r--r--wifi/java/android/net/wifi/WifiStateTracker.java10
5 files changed, 123 insertions, 146 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);
+
}
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index ae4e168..859353a 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -313,21 +313,21 @@ public class ConnectivityService extends IConnectivityManager.Stub {
switch (mNetAttributes[netType].mRadio) {
case ConnectivityManager.TYPE_WIFI:
if (DBG) Slog.v(TAG, "Starting Wifi Service.");
- WifiStateTracker wst = new WifiStateTracker(context, mHandler);
+ WifiStateTracker wst = new WifiStateTracker();
WifiService wifiService = new WifiService(context);
ServiceManager.addService(Context.WIFI_SERVICE, wifiService);
wifiService.checkAndStartWifi();
mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
- wst.startMonitoring();
+ wst.startMonitoring(context, mHandler);
//TODO: as part of WWS refactor, create only when needed
mWifiWatchdogService = new WifiWatchdogService(context);
break;
case ConnectivityManager.TYPE_MOBILE:
- mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
- netType, mNetAttributes[netType].mName);
- mNetTrackers[netType].startMonitoring();
+ mNetTrackers[netType] = new MobileDataStateTracker(netType,
+ mNetAttributes[netType].mName);
+ mNetTrackers[netType].startMonitoring(context, mHandler);
if (noMobileData) {
if (DBG) Slog.d(TAG, "tearing down Mobile networks due to setting");
mNetTrackers[netType].teardown();
@@ -1205,18 +1205,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
sendConnectedBroadcast(info);
}
- private void handleNotificationChange(boolean visible, int id,
- Notification notification) {
- NotificationManager notificationManager = (NotificationManager) mContext
- .getSystemService(Context.NOTIFICATION_SERVICE);
-
- if (visible) {
- notificationManager.notify(id, notification);
- } else {
- notificationManager.cancel(id);
- }
- }
-
/**
* After a change in the connectivity state of a network. We're mainly
* concerned with making sure that the list of DNS servers is set up
@@ -1608,25 +1596,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
handleConnect(info);
}
break;
-
- case NetworkStateTracker.EVENT_NOTIFICATION_CHANGED:
- handleNotificationChange(msg.arg1 == 1, msg.arg2,
- (Notification) msg.obj);
- break;
-
case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
// TODO - make this handle ip/proxy/gateway/dns changes
info = (NetworkInfo) msg.obj;
type = info.getType();
handleDnsConfigurationChange(type);
break;
- case NetworkStateTracker.EVENT_ROAMING_CHANGED:
- // fill me in
- break;
-
- case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED:
- // fill me in
- break;
case NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK:
FeatureUser u = (FeatureUser)msg.obj;
u.expire();
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 3ab6553..064d47f 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -1387,9 +1387,7 @@ public class WifiService extends IWifiManager.Stub {
}
if (mNotification == null) {
- // Cache the Notification mainly so we can remove the
- // EVENT_NOTIFICATION_CHANGED message with this Notification from
- // the queue later
+ // Cache the Notification object.
mNotification = new Notification();
mNotification.when = 0;
mNotification.icon = ICON_NETWORKS_AVAILABLE;
@@ -1408,30 +1406,10 @@ public class WifiService extends IWifiManager.Stub {
mNotificationRepeatTime = System.currentTimeMillis() + NOTIFICATION_REPEAT_DELAY_MS;
notificationManager.notify(ICON_NETWORKS_AVAILABLE, mNotification);
- /*
- * TODO: Clean up connectivity service & remove this
- */
- /* message = mCsHandler.obtainMessage(EVENT_NOTIFICATION_CHANGED, 1,
- ICON_NETWORKS_AVAILABLE, mNotification); */
-
-
} else {
-
notificationManager.cancel(ICON_NETWORKS_AVAILABLE);
- /*
- * TODO: Clean up connectivity service & remove this
- */
- /*
- // Remove any pending messages to show the notification
- mCsHandler.removeMessages(EVENT_NOTIFICATION_CHANGED, mNotification);
-
- message = mCsHandler.obtainMessage(EVENT_NOTIFICATION_CHANGED, 0,
- ICON_NETWORKS_AVAILABLE);
- */
}
- //mCsHandler.sendMessageDelayed(message, delay);
-
mNotificationShown = visible;
}
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java
index 8e1b236..a5f62c1 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -56,10 +56,7 @@ public class WifiStateTracker implements NetworkStateTracker {
private BroadcastReceiver mWifiStateReceiver;
private WifiManager mWifiManager;
- public WifiStateTracker(Context context, Handler target) {
- mCsHandler = target;
- mContext = context;
-
+ public WifiStateTracker() {
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0, NETWORKTYPE, "");
mNetworkProperties = new NetworkProperties();
@@ -80,7 +77,10 @@ public class WifiStateTracker implements NetworkStateTracker {
/**
* Begin monitoring wifi connectivity
*/
- public void startMonitoring() {
+ public void startMonitoring(Context context, Handler target) {
+ mCsHandler = target;
+ mContext = context;
+
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);