resolved conflicts for merge of b998f311 to gingerbread-plus-aosp
Change-Id: I7ceb0b624e78d85542d1c36bfabeb5dc31961505
diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java
index cb4dc9a..5d4b099 100644
--- a/core/java/android/net/NetworkUtils.java
+++ b/core/java/android/net/NetworkUtils.java
@@ -194,4 +194,19 @@
}
return addRoute(interfaceName, dstStr, prefixLength, gwStr) == 0;
}
+
+ public static int v4StringToInt(String str) {
+ int result = 0;
+ String[] array = str.split("\\.");
+ if (array.length != 4) return 0;
+ try {
+ result = Integer.parseInt(array[3]);
+ result = (result << 8) + Integer.parseInt(array[2]);
+ result = (result << 8) + Integer.parseInt(array[1]);
+ result = (result << 8) + Integer.parseInt(array[0]);
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ return result;
+ }
}
diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp
index 6b7f55e..6575b9a 100644
--- a/core/jni/android_net_NetUtils.cpp
+++ b/core/jni/android_net_NetUtils.cpp
@@ -22,8 +22,28 @@
#include <utils/Log.h>
#include <arpa/inet.h>
-#include <netutils/ifc.h>
-#include <netutils/dhcp.h>
+extern "C" {
+int ifc_enable(const char *ifname);
+int ifc_disable(const char *ifname);
+int ifc_add_route(const char *ifname, const char *destStr, uint32_t prefixLen, const char *gwStr);
+int ifc_remove_host_routes(const char *ifname);
+int ifc_get_default_route(const char *ifname);
+int ifc_remove_default_route(const char *ifname);
+int ifc_reset_connections(const char *ifname);
+int ifc_configure(const char *ifname, in_addr_t ipaddr, in_addr_t netmask, in_addr_t gateway, in_addr_t dns1, in_addr_t dns2);
+
+int dhcp_do_request(const char *ifname,
+ in_addr_t *ipaddr,
+ in_addr_t *gateway,
+ in_addr_t *mask,
+ in_addr_t *dns1,
+ in_addr_t *dns2,
+ in_addr_t *server,
+ uint32_t *lease);
+int dhcp_stop(const char *ifname);
+int dhcp_release_lease(const char *ifname);
+char *dhcp_get_errmsg();
+}
#define NETUTILS_PKG_NAME "android/net/NetworkUtils"
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 9edce20..4c81380 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -585,7 +585,7 @@
!network.isTeardownRequested()) {
if (ni.isConnected() == true) {
// add the pid-specific dns
- handleDnsConfigurationChange();
+ handleDnsConfigurationChange(networkType);
if (DBG) Slog.d(TAG, "special network already active");
return Phone.APN_ALREADY_ACTIVE;
}
@@ -920,7 +920,6 @@
}
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
- intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
if (info.isFailover()) {
intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
@@ -945,7 +944,7 @@
}
}
// do this before we broadcast the change
- handleConnectivityChange();
+ handleConnectivityChange(prevNetType);
sendStickyBroadcast(intent);
/*
@@ -1036,7 +1035,6 @@
private void sendConnectedBroadcast(NetworkInfo info) {
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
- intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
if (info.isFailover()) {
intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
@@ -1074,7 +1072,6 @@
}
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
- intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
if (getActiveNetworkInfo() == null) {
intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
@@ -1101,9 +1098,6 @@
}
}
- // do this before we broadcast the change
- handleConnectivityChange();
-
sendStickyBroadcast(intent);
/*
* If the failover network is already connected, then immediately send
@@ -1174,7 +1168,7 @@
}
thisNet.setTeardownRequested(false);
thisNet.updateNetworkSettings();
- handleConnectivityChange();
+ handleConnectivityChange(type);
sendConnectedBroadcast(info);
}
@@ -1201,38 +1195,29 @@
}
/**
- * After any kind of change in the connectivity state of any network,
- * make sure that anything that depends on the connectivity state of
- * more than one network is set up correctly. We're mainly concerned
- * with making sure that the list of DNS servers is set up according
- * to which networks are connected, and ensuring that the right routing
- * table entries exist.
+ * After a change in the connectivity state of any network, We're mainly
+ * concerned with making sure that the list of DNS servers is setupup
+ * according to which networks are connected, and ensuring that the
+ * right routing table entries exist.
*/
- private void handleConnectivityChange() {
+ private void handleConnectivityChange(int netType) {
/*
* If a non-default network is enabled, add the host routes that
- * will allow it's DNS servers to be accessed. Only
- * If both mobile and wifi are enabled, add the host routes that
- * will allow MMS traffic to pass on the mobile network. But
- * remove the default route for the mobile network, so that there
- * will be only one default route, to ensure that all traffic
- * except MMS will travel via Wi-Fi.
+ * will allow it's DNS servers to be accessed.
*/
- handleDnsConfigurationChange();
+ handleDnsConfigurationChange(netType);
- for (int netType : mPriorityList) {
- if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
- if (mNetAttributes[netType].isDefault()) {
- mNetTrackers[netType].addDefaultRoute();
- } else {
- mNetTrackers[netType].addPrivateDnsRoutes();
- }
+ if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
+ if (mNetAttributes[netType].isDefault()) {
+ mNetTrackers[netType].addDefaultRoute();
} else {
- if (mNetAttributes[netType].isDefault()) {
- mNetTrackers[netType].removeDefaultRoute();
- } else {
- mNetTrackers[netType].removePrivateDnsRoutes();
- }
+ mNetTrackers[netType].addPrivateDnsRoutes();
+ }
+ } else {
+ if (mNetAttributes[netType].isDefault()) {
+ mNetTrackers[netType].removeDefaultRoute();
+ } else {
+ mNetTrackers[netType].removePrivateDnsRoutes();
}
}
}
@@ -1303,41 +1288,36 @@
SystemProperties.set("net.dnschange", "" + (n+1));
}
- private void handleDnsConfigurationChange() {
+ private void handleDnsConfigurationChange(int netType) {
// add default net's dns entries
- for (int x = mPriorityList.length-1; x>= 0; x--) {
- int netType = mPriorityList[x];
- NetworkStateTracker nt = mNetTrackers[netType];
- if (nt != null && nt.getNetworkInfo().isConnected() &&
- !nt.isTeardownRequested()) {
- String[] dnsList = nt.getNameServers();
- if (mNetAttributes[netType].isDefault()) {
- int j = 1;
- for (String dns : dnsList) {
- if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
- if (DBG) {
- Slog.d(TAG, "adding dns " + dns + " for " +
- nt.getNetworkInfo().getTypeName());
- }
- SystemProperties.set("net.dns" + j++, dns);
+ NetworkStateTracker nt = mNetTrackers[netType];
+ if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
+ String[] dnsList = nt.getNameServers();
+ if (mNetAttributes[netType].isDefault()) {
+ int j = 1;
+ for (String dns : dnsList) {
+ if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
+ if (DBG) {
+ Slog.d(TAG, "adding dns " + dns + " for " +
+ nt.getNetworkInfo().getTypeName());
}
+ SystemProperties.set("net.dns" + j++, dns);
}
- for (int k=j ; k<mNumDnsEntries; k++) {
- if (DBG) Slog.d(TAG, "erasing net.dns" + k);
- SystemProperties.set("net.dns" + k, "");
- }
- mNumDnsEntries = j;
- } else {
- // set per-pid dns for attached secondary nets
- List pids = mNetRequestersPids[netType];
- for (int y=0; y< pids.size(); y++) {
- Integer pid = (Integer)pids.get(y);
- writePidDns(dnsList, pid.intValue());
- }
+ }
+ for (int k=j ; k<mNumDnsEntries; k++) {
+ if (DBG) Slog.d(TAG, "erasing net.dns" + k);
+ SystemProperties.set("net.dns" + k, "");
+ }
+ mNumDnsEntries = j;
+ } else {
+ // set per-pid dns for attached secondary nets
+ List pids = mNetRequestersPids[netType];
+ for (int y=0; y< pids.size(); y++) {
+ Integer pid = (Integer)pids.get(y);
+ writePidDns(dnsList, pid.intValue());
}
}
}
-
bumpDns();
}
@@ -1468,9 +1448,12 @@
case NetworkStateTracker.EVENT_NOTIFICATION_CHANGED:
handleNotificationChange(msg.arg1 == 1, msg.arg2,
(Notification) msg.obj);
+ break;
case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
- handleDnsConfigurationChange();
+ info = (NetworkInfo) msg.obj;
+ type = info.getType();
+ handleDnsConfigurationChange(type);
break;
case NetworkStateTracker.EVENT_ROAMING_CHANGED: