Update comments and documentation in net type prop change
am: ea26baf9ff
Change-Id: I0fe7d537d46ab0b4bcd6521162e35fcb719f13f9
This commit is contained in:
@@ -44,6 +44,7 @@ import android.os.ConditionVariable;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
@@ -71,6 +72,12 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
||||
private final Handler mHandler;
|
||||
private final Context mContext;
|
||||
|
||||
public static class ConfigurationException extends AndroidRuntimeException {
|
||||
public ConfigurationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public EthernetNetworkFactory(Handler handler, Context context, NetworkCapabilities filter) {
|
||||
super(handler.getLooper(), context, NETWORK_TYPE, filter);
|
||||
|
||||
@@ -358,8 +365,8 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
||||
legacyType = getLegacyType(transportTypes[0]);
|
||||
} else {
|
||||
// Should never happen as transport is always one of ETHERNET or a valid override
|
||||
Log.w(TAG, "There is no transport type associated with network interface '"
|
||||
+ mLinkProperties.getInterfaceName() + "' -- Legacy type set to TYPE_NONE");
|
||||
throw new ConfigurationException("Network Capabilities do not have an associated "
|
||||
+ "transport type.");
|
||||
}
|
||||
|
||||
mHwAddress = hwAddress;
|
||||
@@ -410,8 +417,8 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
||||
|
||||
int[] transportTypes = mCapabilities.getTransportTypes();
|
||||
if (transportTypes.length < 1) {
|
||||
Log.w(TAG, "There is no transport type associated with network interface '"
|
||||
+ mLinkProperties.getInterfaceName() + "' -- Score set to zero");
|
||||
Log.w(TAG, "Network interface '" + mLinkProperties.getInterfaceName() + "' has no "
|
||||
+ "transport type associated with it. Score set to zero");
|
||||
return 0;
|
||||
}
|
||||
TransportInfo transportInfo = sTransports.get(transportTypes[0], /* if dne */ null);
|
||||
@@ -532,7 +539,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
||||
mNetworkAgent.sendLinkProperties(mLinkProperties);
|
||||
|
||||
// As a note, getNetworkScore() is fairly expensive to calculate. This is fine for now
|
||||
// since the agent isn't update frequently. Consider caching the score in the future if
|
||||
// since the agent isn't updated frequently. Consider caching the score in the future if
|
||||
// agent updating is required more often
|
||||
mNetworkAgent.sendNetworkScore(getNetworkScore());
|
||||
}
|
||||
|
||||
@@ -337,10 +337,10 @@ final class EthernetTracker {
|
||||
* @param clearDefaultCapabilities Indicates whether or not to clear any default capabilities
|
||||
* @param commaSeparatedCapabilities A comma separated string list of integer encoded
|
||||
* NetworkCapability.NET_CAPABILITY_* values
|
||||
* @param overrideTransport A string representing a single override transport type, must be one
|
||||
* of the NetworkCapability.TRANSPORT_* values. TRANSPORT_VPN is
|
||||
* not supported. Errors with input will cause the override to
|
||||
* be ignored.
|
||||
* @param overrideTransport A string representing a single integer encoded override transport
|
||||
* type. Must be one of the NetworkCapability.TRANSPORT_*
|
||||
* values. TRANSPORT_VPN is not supported. Errors with input
|
||||
* will cause the override to be ignored.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static NetworkCapabilities createNetworkCapabilities(
|
||||
@@ -363,14 +363,14 @@ final class EthernetTracker {
|
||||
if (parsedTransport == NetworkCapabilities.TRANSPORT_VPN
|
||||
|| parsedTransport == NetworkCapabilities.TRANSPORT_WIFI_AWARE
|
||||
|| parsedTransport == NetworkCapabilities.TRANSPORT_LOWPAN) {
|
||||
Log.e(TAG, "Override transport '" + parsedTransport + "' is not supported -- "
|
||||
Log.e(TAG, "Override transport '" + parsedTransport + "' is not supported. "
|
||||
+ "Defaulting to TRANSPORT_ETHERNET");
|
||||
} else {
|
||||
transport = parsedTransport;
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
Log.e(TAG, "Override transport type '" + overrideTransport + "' could not be parsed"
|
||||
+ "-- Defaulting to TRANSPORT_ETHERNET");
|
||||
Log.e(TAG, "Override transport type '" + overrideTransport + "' "
|
||||
+ "could not be parsed. Defaulting to TRANSPORT_ETHERNET");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,8 +379,8 @@ final class EthernetTracker {
|
||||
try {
|
||||
nc.addTransportType(transport);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
Log.e(TAG, transport + " is not a valid NetworkCapability.TRANSPORT_* value"
|
||||
+ " -- Defaulting to TRANSPORT_ETHERNET");
|
||||
Log.e(TAG, transport + " is not a valid NetworkCapability.TRANSPORT_* value. "
|
||||
+ "Defaulting to TRANSPORT_ETHERNET");
|
||||
nc.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET);
|
||||
}
|
||||
|
||||
|
||||
@@ -160,11 +160,11 @@ public class EthernetTrackerTest {
|
||||
|
||||
// Empty capabilities and transports lists with a "please clear defaults" should
|
||||
// yield an empty capabilities set with TRANPORT_ETHERNET
|
||||
assertNetworkCapabilities(defaultEthernetCleared, true, "", "");
|
||||
assertParsedNetworkCapabilities(defaultEthernetCleared, true, "", "");
|
||||
|
||||
// Empty capabilities and transports without the clear defaults flag should return the
|
||||
// default capabilities set with TRANSPORT_ETHERNET
|
||||
assertNetworkCapabilities(
|
||||
assertParsedNetworkCapabilities(
|
||||
new NetworkCapabilitiesBuilder()
|
||||
.setLinkUpstreamBandwidthKbps(100000)
|
||||
.setLinkDownstreamBandwidthKbps(100000)
|
||||
@@ -174,7 +174,7 @@ public class EthernetTrackerTest {
|
||||
|
||||
// A list of capabilities without the clear defaults flag should return the default
|
||||
// capabilities, mixed with the desired capabilities, and TRANSPORT_ETHERNET
|
||||
assertNetworkCapabilities(
|
||||
assertParsedNetworkCapabilities(
|
||||
new NetworkCapabilitiesBuilder()
|
||||
.setLinkUpstreamBandwidthKbps(100000)
|
||||
.setLinkDownstreamBandwidthKbps(100000)
|
||||
@@ -186,15 +186,15 @@ public class EthernetTrackerTest {
|
||||
|
||||
// Adding a list of capabilities with a clear defaults will leave exactly those capabilities
|
||||
// with a default TRANSPORT_ETHERNET since no overrides are specified
|
||||
assertNetworkCapabilities(ethernetClearedWithCommonCaps, true, "12,13,14,15", "");
|
||||
assertParsedNetworkCapabilities(ethernetClearedWithCommonCaps, true, "12,13,14,15", "");
|
||||
|
||||
// Adding any invalid capabilities to the list will cause them to be ignored
|
||||
assertNetworkCapabilities(ethernetClearedWithCommonCaps, true, "12,13,14,15,65,73", "");
|
||||
assertNetworkCapabilities(ethernetClearedWithCommonCaps, true, "12,13,14,15,abcdefg", "");
|
||||
assertParsedNetworkCapabilities(ethernetClearedWithCommonCaps, true, "12,13,14,15,65,73", "");
|
||||
assertParsedNetworkCapabilities(ethernetClearedWithCommonCaps, true, "12,13,14,15,abcdefg", "");
|
||||
|
||||
// Adding a valid override transport will remove the default TRANSPORT_ETHERNET transport
|
||||
// and apply only the override to the capabiltities object
|
||||
assertNetworkCapabilities(
|
||||
assertParsedNetworkCapabilities(
|
||||
new NetworkCapabilitiesBuilder()
|
||||
.clearAll()
|
||||
.setLinkUpstreamBandwidthKbps(100000)
|
||||
@@ -202,7 +202,7 @@ public class EthernetTrackerTest {
|
||||
.addTransport(0)
|
||||
.build(),
|
||||
true, "", "0");
|
||||
assertNetworkCapabilities(
|
||||
assertParsedNetworkCapabilities(
|
||||
new NetworkCapabilitiesBuilder()
|
||||
.clearAll()
|
||||
.setLinkUpstreamBandwidthKbps(100000)
|
||||
@@ -210,7 +210,7 @@ public class EthernetTrackerTest {
|
||||
.addTransport(1)
|
||||
.build(),
|
||||
true, "", "1");
|
||||
assertNetworkCapabilities(
|
||||
assertParsedNetworkCapabilities(
|
||||
new NetworkCapabilitiesBuilder()
|
||||
.clearAll()
|
||||
.setLinkUpstreamBandwidthKbps(100000)
|
||||
@@ -218,7 +218,7 @@ public class EthernetTrackerTest {
|
||||
.addTransport(2)
|
||||
.build(),
|
||||
true, "", "2");
|
||||
assertNetworkCapabilities(
|
||||
assertParsedNetworkCapabilities(
|
||||
new NetworkCapabilitiesBuilder()
|
||||
.clearAll()
|
||||
.setLinkUpstreamBandwidthKbps(100000)
|
||||
@@ -228,22 +228,22 @@ public class EthernetTrackerTest {
|
||||
true, "", "3");
|
||||
|
||||
// "4" is TRANSPORT_VPN, which is unsupported. Should default back to TRANPORT_ETHERNET
|
||||
assertNetworkCapabilities(defaultEthernetCleared, true, "", "4");
|
||||
assertParsedNetworkCapabilities(defaultEthernetCleared, true, "", "4");
|
||||
|
||||
// "5" is TRANSPORT_WIFI_AWARE, which is currently supported due to no legacy TYPE_NONE
|
||||
// conversion. When that becomes available, this test must be updated
|
||||
assertNetworkCapabilities(defaultEthernetCleared, true, "", "5");
|
||||
assertParsedNetworkCapabilities(defaultEthernetCleared, true, "", "5");
|
||||
|
||||
// "6" is TRANSPORT_LOWPAN, which is currently supported due to no legacy TYPE_NONE
|
||||
// conversion. When that becomes available, this test must be updated
|
||||
assertNetworkCapabilities(defaultEthernetCleared, true, "", "6");
|
||||
assertParsedNetworkCapabilities(defaultEthernetCleared, true, "", "6");
|
||||
|
||||
// Adding an invalid override transport will leave the transport as TRANSPORT_ETHERNET
|
||||
assertNetworkCapabilities(defaultEthernetCleared,true, "", "100");
|
||||
assertNetworkCapabilities(defaultEthernetCleared, true, "", "abcdefg");
|
||||
assertParsedNetworkCapabilities(defaultEthernetCleared,true, "", "100");
|
||||
assertParsedNetworkCapabilities(defaultEthernetCleared, true, "", "abcdefg");
|
||||
|
||||
// Ensure the adding of both capabilities and transports work
|
||||
assertNetworkCapabilities(
|
||||
assertParsedNetworkCapabilities(
|
||||
new NetworkCapabilitiesBuilder()
|
||||
.clearAll()
|
||||
.setLinkUpstreamBandwidthKbps(100000)
|
||||
@@ -257,10 +257,10 @@ public class EthernetTrackerTest {
|
||||
true, "12,13,14,15", "3");
|
||||
|
||||
// Ensure order does not matter for capability list
|
||||
assertNetworkCapabilities(ethernetClearedWithCommonCaps, true, "13,12,15,14", "");
|
||||
assertParsedNetworkCapabilities(ethernetClearedWithCommonCaps, true, "13,12,15,14", "");
|
||||
}
|
||||
|
||||
private void assertNetworkCapabilities(NetworkCapabilities expectedNetworkCapabilities,
|
||||
private void assertParsedNetworkCapabilities(NetworkCapabilities expectedNetworkCapabilities,
|
||||
boolean clearCapabilties, String configCapabiltiies,String configTransports) {
|
||||
assertEquals(expectedNetworkCapabilities,
|
||||
EthernetTracker.createNetworkCapabilities(clearCapabilties, configCapabiltiies,
|
||||
|
||||
Reference in New Issue
Block a user