Merge "Tighten test for warm sim and add more debug." into klp-dev
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index 43d6b71..b4d07a1 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -66,6 +66,7 @@
private String mDomains;
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
private ProxyProperties mHttpProxy;
+ private int mMtu;
// Stores the properties of links that are "stacked" above this link.
// Indexed by interface name to allow modification and to prevent duplicates being added.
@@ -104,6 +105,7 @@
for (LinkProperties l: source.mStackedLinks.values()) {
addStackedLink(l);
}
+ setMtu(source.getMtu());
}
}
@@ -223,6 +225,14 @@
mDomains = domains;
}
+ public void setMtu(int mtu) {
+ mMtu = mtu;
+ }
+
+ public int getMtu() {
+ return mMtu;
+ }
+
private RouteInfo routeWithInterface(RouteInfo route) {
return new RouteInfo(
route.getDestination(),
@@ -322,6 +332,7 @@
mRoutes.clear();
mHttpProxy = null;
mStackedLinks.clear();
+ mMtu = 0;
}
/**
@@ -346,6 +357,8 @@
String domainName = "Domains: " + mDomains;
+ String mtu = "MTU: " + mMtu;
+
String routes = " Routes: [";
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
routes += "] ";
@@ -359,7 +372,8 @@
}
stacked += "] ";
}
- return "{" + ifaceName + linkAddresses + routes + dns + domainName + proxy + stacked + "}";
+ return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
+ + proxy + stacked + "}";
}
/**
@@ -474,6 +488,16 @@
return true;
}
+ /**
+ * Compares this {@code LinkProperties} MTU against the target
+ *
+ * @param target LinkProperties to compare.
+ * @return {@code true} if both are identical, {@code false} otherwise.
+ */
+ public boolean isIdenticalMtu(LinkProperties target) {
+ return getMtu() == target.getMtu();
+ }
+
@Override
/**
* Compares this {@code LinkProperties} instance against the target
@@ -505,7 +529,8 @@
isIdenticalDnses(target) &&
isIdenticalRoutes(target) &&
isIdenticalHttpProxy(target) &&
- isIdenticalStackedLinks(target);
+ isIdenticalStackedLinks(target) &&
+ isIdenticalMtu(target);
}
/**
@@ -607,7 +632,8 @@
+ ((null == mDomains) ? 0 : mDomains.hashCode())
+ mRoutes.size() * 41
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
- + mStackedLinks.hashCode() * 47);
+ + mStackedLinks.hashCode() * 47)
+ + mMtu * 51;
}
/**
@@ -625,7 +651,7 @@
dest.writeByteArray(d.getAddress());
}
dest.writeString(mDomains);
-
+ dest.writeInt(mMtu);
dest.writeInt(mRoutes.size());
for(RouteInfo route : mRoutes) {
dest.writeParcelable(route, flags);
@@ -664,6 +690,7 @@
} catch (UnknownHostException e) { }
}
netProp.setDomains(in.readString());
+ netProp.setMtu(in.readInt());
addressCount = in.readInt();
for (int i=0; i<addressCount; i++) {
netProp.addRoute((RouteInfo)in.readParcelable(null));
diff --git a/core/tests/coretests/src/android/net/LinkPropertiesTest.java b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
index 7e70c6b..e63f6b0 100644
--- a/core/tests/coretests/src/android/net/LinkPropertiesTest.java
+++ b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
@@ -33,6 +33,7 @@
private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1");
private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1");
private static String NAME = "qmi0";
+ private static int MTU = 1500;
private static LinkAddress LINKADDRV4 = new LinkAddress(ADDRV4, 32);
private static LinkAddress LINKADDRV6 = new LinkAddress(ADDRV6, 128);
@@ -57,6 +58,9 @@
assertTrue(source.isIdenticalStackedLinks(target));
assertTrue(target.isIdenticalStackedLinks(source));
+ assertTrue(source.isIdenticalMtu(target));
+ assertTrue(target.isIdenticalMtu(source));
+
// Check result of equals().
assertTrue(source.equals(target));
assertTrue(target.equals(source));
@@ -88,6 +92,7 @@
// set 2 gateways
source.addRoute(new RouteInfo(GATEWAY1));
source.addRoute(new RouteInfo(GATEWAY2));
+ source.setMtu(MTU);
LinkProperties target = new LinkProperties();
@@ -99,6 +104,7 @@
target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertLinkPropertiesEqual(source, target);
@@ -111,6 +117,7 @@
target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertFalse(source.equals(target));
target.clear();
@@ -123,6 +130,7 @@
target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertFalse(source.equals(target));
target.clear();
@@ -134,6 +142,7 @@
target.addDns(DNS2);
target.addRoute(new RouteInfo(GATEWAY1));
target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
assertFalse(source.equals(target));
target.clear();
@@ -145,6 +154,19 @@
// change gateway
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2")));
target.addRoute(new RouteInfo(GATEWAY2));
+ target.setMtu(MTU);
+ assertFalse(source.equals(target));
+
+ target.clear();
+ target.setInterfaceName(NAME);
+ target.addLinkAddress(LINKADDRV4);
+ target.addLinkAddress(LINKADDRV6);
+ target.addDns(DNS1);
+ target.addDns(DNS2);
+ target.addRoute(new RouteInfo(GATEWAY1));
+ target.addRoute(new RouteInfo(GATEWAY2));
+ // change mtu
+ target.setMtu(1440);
assertFalse(source.equals(target));
} catch (Exception e) {
@@ -167,6 +189,7 @@
// set 2 gateways
source.addRoute(new RouteInfo(GATEWAY1));
source.addRoute(new RouteInfo(GATEWAY2));
+ source.setMtu(MTU);
LinkProperties target = new LinkProperties();
// Exchange order
@@ -177,6 +200,7 @@
target.addDns(DNS1);
target.addRoute(new RouteInfo(GATEWAY2));
target.addRoute(new RouteInfo(GATEWAY1));
+ target.setMtu(MTU);
assertLinkPropertiesEqual(source, target);
} catch (Exception e) {
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 759dce7..02a78de 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -184,7 +184,7 @@
private static final String ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED =
"android.net.ConnectivityService.action.PKT_CNT_SAMPLE_INTERVAL_ELAPSED";
- private static final int SAMPLE_INTERVAL_ELAPSED_REQURST_CODE = 0;
+ private static final int SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE = 0;
private PendingIntent mSampleIntervalElapsedIntent;
@@ -661,7 +661,7 @@
// start network sampling ..
Intent intent = new Intent(ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED, null);
mSampleIntervalElapsedIntent = PendingIntent.getBroadcast(mContext,
- SAMPLE_INTERVAL_ELAPSED_REQURST_CODE, intent, 0);
+ SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE, intent, 0);
mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
setAlarm(DEFAULT_START_SAMPLING_INTERVAL_IN_SECONDS * 1000, mSampleIntervalElapsedIntent);
@@ -2299,6 +2299,7 @@
}
thisNet.setTeardownRequested(false);
updateNetworkSettings(thisNet);
+ updateMtuSizeSettings(thisNet);
handleConnectivityChange(newNetType, false);
sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
@@ -2636,6 +2637,26 @@
return routesChanged;
}
+ /**
+ * Reads the network specific MTU size from reources.
+ * and set it on it's iface.
+ */
+ private void updateMtuSizeSettings(NetworkStateTracker nt) {
+ final String iface = nt.getLinkProperties().getInterfaceName();
+ final int mtu = nt.getLinkProperties().getMtu();
+
+ if (mtu < 68 || mtu > 10000) {
+ loge("Unexpected mtu value: " + nt);
+ return;
+ }
+
+ try {
+ if (VDBG) log("Setting MTU size: " + iface + ", " + mtu);
+ mNetd.setMtu(iface, mtu);
+ } catch (Exception e) {
+ Slog.e(TAG, "exception in setMtu()" + e);
+ }
+ }
/**
* Reads the network specific TCP buffer sizes from SystemProperties
@@ -3017,7 +3038,7 @@
public void handleMessage(Message msg) {
NetworkInfo info;
switch (msg.what) {
- case EVENT_CLEAR_NET_TRANSITION_WAKELOCK:
+ case EVENT_CLEAR_NET_TRANSITION_WAKELOCK: {
String causedBy = null;
synchronized (ConnectivityService.this) {
if (msg.arg1 == mNetTransitionWakeLockSerialNumber &&
@@ -3030,49 +3051,44 @@
log("NetTransition Wakelock for " + causedBy + " released by timeout");
}
break;
- case EVENT_RESTORE_DEFAULT_NETWORK:
+ }
+ case EVENT_RESTORE_DEFAULT_NETWORK: {
FeatureUser u = (FeatureUser)msg.obj;
u.expire();
break;
- case EVENT_INET_CONDITION_CHANGE:
- {
+ }
+ case EVENT_INET_CONDITION_CHANGE: {
int netType = msg.arg1;
int condition = msg.arg2;
handleInetConditionChange(netType, condition);
break;
}
- case EVENT_INET_CONDITION_HOLD_END:
- {
+ case EVENT_INET_CONDITION_HOLD_END: {
int netType = msg.arg1;
int sequence = msg.arg2;
handleInetConditionHoldEnd(netType, sequence);
break;
}
- case EVENT_SET_NETWORK_PREFERENCE:
- {
+ case EVENT_SET_NETWORK_PREFERENCE: {
int preference = msg.arg1;
handleSetNetworkPreference(preference);
break;
}
- case EVENT_SET_MOBILE_DATA:
- {
+ case EVENT_SET_MOBILE_DATA: {
boolean enabled = (msg.arg1 == ENABLED);
handleSetMobileData(enabled);
break;
}
- case EVENT_APPLY_GLOBAL_HTTP_PROXY:
- {
+ case EVENT_APPLY_GLOBAL_HTTP_PROXY: {
handleDeprecatedGlobalHttpProxy();
break;
}
- case EVENT_SET_DEPENDENCY_MET:
- {
+ case EVENT_SET_DEPENDENCY_MET: {
boolean met = (msg.arg1 == ENABLED);
handleSetDependencyMet(msg.arg2, met);
break;
}
- case EVENT_SEND_STICKY_BROADCAST_INTENT:
- {
+ case EVENT_SEND_STICKY_BROADCAST_INTENT: {
Intent intent = (Intent)msg.obj;
sendStickyBroadcast(intent);
break;
@@ -3101,10 +3117,12 @@
log("EVENT_ENABLE_FAIL_FAST_MOBILE_DATA: stale arg1:" + msg.arg1
+ " != tag:" + tag);
}
+ break;
}
- case EVENT_SAMPLE_INTERVAL_ELAPSED:
+ case EVENT_SAMPLE_INTERVAL_ELAPSED: {
handleNetworkSamplingTimeout();
break;
+ }
}
}
}
@@ -4789,4 +4807,3 @@
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, wakeupTime, intent);
}
}
-