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