Removing unused int network score from eth factory am: 68c4a5108b am: 21bbe6f4a5
Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/net/ethernet/+/1891859 Change-Id: I1934112b51a2c4002fbd2c29a31562f2c1ae3a3f
This commit is contained in:
@@ -22,6 +22,7 @@ import android.net.NetworkAgent;
|
|||||||
import android.net.NetworkAgentConfig;
|
import android.net.NetworkAgentConfig;
|
||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.NetworkProvider;
|
import android.net.NetworkProvider;
|
||||||
|
import android.net.NetworkScore;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -41,11 +42,10 @@ public class EthernetNetworkAgent extends NetworkAgent {
|
|||||||
@NonNull Looper looper,
|
@NonNull Looper looper,
|
||||||
@NonNull NetworkCapabilities nc,
|
@NonNull NetworkCapabilities nc,
|
||||||
@NonNull LinkProperties lp,
|
@NonNull LinkProperties lp,
|
||||||
int networkScore,
|
|
||||||
@NonNull NetworkAgentConfig config,
|
@NonNull NetworkAgentConfig config,
|
||||||
@Nullable NetworkProvider provider,
|
@Nullable NetworkProvider provider,
|
||||||
@NonNull Callbacks cb) {
|
@NonNull Callbacks cb) {
|
||||||
super(context, looper, TAG, nc, lp, networkScore, config, provider);
|
super(context, looper, TAG, nc, lp, new NetworkScore.Builder().build(), config, provider);
|
||||||
mCallbacks = cb;
|
mCallbacks = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,11 +79,9 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EthernetNetworkAgent makeEthernetNetworkAgent(Context context, Looper looper,
|
public EthernetNetworkAgent makeEthernetNetworkAgent(Context context, Looper looper,
|
||||||
NetworkCapabilities nc, LinkProperties lp, int networkScore,
|
NetworkCapabilities nc, LinkProperties lp, NetworkAgentConfig config,
|
||||||
NetworkAgentConfig config, NetworkProvider provider,
|
NetworkProvider provider, EthernetNetworkAgent.Callbacks cb) {
|
||||||
EthernetNetworkAgent.Callbacks cb) {
|
return new EthernetNetworkAgent(context, looper, nc, lp, config, provider, cb);
|
||||||
return new EthernetNetworkAgent(context, looper, nc, lp, networkScore, config, provider,
|
|
||||||
cb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InterfaceParams getNetworkInterfaceByName(String name) {
|
public InterfaceParams getNetworkInterfaceByName(String name) {
|
||||||
@@ -293,49 +291,24 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
private @Nullable IpConfiguration mIpConfig;
|
private @Nullable IpConfiguration mIpConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object to contain all transport type information, including base network score and
|
* A map of TRANSPORT_* types to legacy transport types available for each type an ethernet
|
||||||
* the legacy transport type it maps to (if any)
|
* interface could propagate.
|
||||||
*/
|
|
||||||
private static class TransportInfo {
|
|
||||||
final int mLegacyType;
|
|
||||||
final int mScore;
|
|
||||||
|
|
||||||
private TransportInfo(int legacyType, int score) {
|
|
||||||
mLegacyType = legacyType;
|
|
||||||
mScore = score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A map of TRANSPORT_* types to TransportInfo, making scoring and legacy type information
|
|
||||||
* available for each type an ethernet interface could propagate.
|
|
||||||
*
|
*
|
||||||
* Unfortunately, base scores for the various transports are not yet centrally located.
|
* There are no legacy type equivalents to LOWPAN or WIFI_AWARE. These types are set to
|
||||||
* They've been lifted from the corresponding NetworkFactory files in the meantime.
|
* TYPE_NONE to match the behavior of their own network factories.
|
||||||
*
|
|
||||||
* Additionally, there are no legacy type equivalents to LOWPAN or WIFI_AWARE. These types
|
|
||||||
* are set to TYPE_NONE to match the behavior of their own network factories.
|
|
||||||
*/
|
*/
|
||||||
private static final SparseArray<TransportInfo> sTransports = new SparseArray();
|
private static final SparseArray<Integer> sTransports = new SparseArray();
|
||||||
static {
|
static {
|
||||||
// LowpanInterfaceTracker.NETWORK_SCORE
|
|
||||||
sTransports.put(NetworkCapabilities.TRANSPORT_LOWPAN,
|
|
||||||
new TransportInfo(ConnectivityManager.TYPE_NONE, 30));
|
|
||||||
// WifiAwareDataPathStateManager.NETWORK_FACTORY_SCORE_AVAIL
|
|
||||||
sTransports.put(NetworkCapabilities.TRANSPORT_WIFI_AWARE,
|
|
||||||
new TransportInfo(ConnectivityManager.TYPE_NONE, 1));
|
|
||||||
// EthernetNetworkFactory.NETWORK_SCORE
|
|
||||||
sTransports.put(NetworkCapabilities.TRANSPORT_ETHERNET,
|
sTransports.put(NetworkCapabilities.TRANSPORT_ETHERNET,
|
||||||
new TransportInfo(ConnectivityManager.TYPE_ETHERNET, 70));
|
ConnectivityManager.TYPE_ETHERNET);
|
||||||
// BluetoothTetheringNetworkFactory.NETWORK_SCORE
|
|
||||||
sTransports.put(NetworkCapabilities.TRANSPORT_BLUETOOTH,
|
sTransports.put(NetworkCapabilities.TRANSPORT_BLUETOOTH,
|
||||||
new TransportInfo(ConnectivityManager.TYPE_BLUETOOTH, 69));
|
ConnectivityManager.TYPE_BLUETOOTH);
|
||||||
// WifiNetworkFactory.SCORE_FILTER / NetworkAgent.WIFI_BASE_SCORE
|
sTransports.put(NetworkCapabilities.TRANSPORT_WIFI, ConnectivityManager.TYPE_WIFI);
|
||||||
sTransports.put(NetworkCapabilities.TRANSPORT_WIFI,
|
|
||||||
new TransportInfo(ConnectivityManager.TYPE_WIFI, 60));
|
|
||||||
// TelephonyNetworkFactory.TELEPHONY_NETWORK_SCORE
|
|
||||||
sTransports.put(NetworkCapabilities.TRANSPORT_CELLULAR,
|
sTransports.put(NetworkCapabilities.TRANSPORT_CELLULAR,
|
||||||
new TransportInfo(ConnectivityManager.TYPE_MOBILE, 50));
|
ConnectivityManager.TYPE_MOBILE);
|
||||||
|
sTransports.put(NetworkCapabilities.TRANSPORT_LOWPAN, ConnectivityManager.TYPE_NONE);
|
||||||
|
sTransports.put(NetworkCapabilities.TRANSPORT_WIFI_AWARE,
|
||||||
|
ConnectivityManager.TYPE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
long refCount = 0;
|
long refCount = 0;
|
||||||
@@ -397,7 +370,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mNetworkFactory = networkFactory;
|
mNetworkFactory = networkFactory;
|
||||||
mDeps = deps;
|
mDeps = deps;
|
||||||
int legacyType = ConnectivityManager.TYPE_NONE;
|
final int legacyType;
|
||||||
int[] transportTypes = mCapabilities.getTransportTypes();
|
int[] transportTypes = mCapabilities.getTransportTypes();
|
||||||
|
|
||||||
if (transportTypes.length > 0) {
|
if (transportTypes.length > 0) {
|
||||||
@@ -432,40 +405,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
* to legacy TYPE_NONE if there is no known conversion
|
* to legacy TYPE_NONE if there is no known conversion
|
||||||
*/
|
*/
|
||||||
private static int getLegacyType(int transport) {
|
private static int getLegacyType(int transport) {
|
||||||
TransportInfo transportInfo = sTransports.get(transport, /* if dne */ null);
|
return sTransports.get(transport, ConnectivityManager.TYPE_NONE);
|
||||||
if (transportInfo != null) {
|
|
||||||
return transportInfo.mLegacyType;
|
|
||||||
}
|
|
||||||
return ConnectivityManager.TYPE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines the network score based on the transport associated with the interface.
|
|
||||||
* Ethernet interfaces could propagate a transport types forward. Since we can't
|
|
||||||
* get more information about the statuses of the interfaces on the other end of the local
|
|
||||||
* interface, we'll best-effort assign the score as the base score of the assigned transport
|
|
||||||
* when the link is up. When the link is down, the score is set to zero.
|
|
||||||
*
|
|
||||||
* This function is called with the purpose of assigning and updating the network score of
|
|
||||||
* the member NetworkAgent.
|
|
||||||
*/
|
|
||||||
private int getNetworkScore() {
|
|
||||||
// never set the network score below 0.
|
|
||||||
if (!mLinkUp) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int[] transportTypes = mCapabilities.getTransportTypes();
|
|
||||||
if (transportTypes.length < 1) {
|
|
||||||
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);
|
|
||||||
if (transportInfo != null) {
|
|
||||||
return transportInfo.mScore;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void start() {
|
private void start() {
|
||||||
@@ -502,8 +442,8 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
.setLegacyExtraInfo(mHwAddress)
|
.setLegacyExtraInfo(mHwAddress)
|
||||||
.build();
|
.build();
|
||||||
mNetworkAgent = mDeps.makeEthernetNetworkAgent(mContext, mHandler.getLooper(),
|
mNetworkAgent = mDeps.makeEthernetNetworkAgent(mContext, mHandler.getLooper(),
|
||||||
mCapabilities, mLinkProperties, getNetworkScore(), config,
|
mCapabilities, mLinkProperties, config, mNetworkFactory.getProvider(),
|
||||||
mNetworkFactory.getProvider(), new EthernetNetworkAgent.Callbacks() {
|
new EthernetNetworkAgent.Callbacks() {
|
||||||
@Override
|
@Override
|
||||||
public void onNetworkUnwanted() {
|
public void onNetworkUnwanted() {
|
||||||
// if mNetworkAgent is null, we have already called stop.
|
// if mNetworkAgent is null, we have already called stop.
|
||||||
@@ -620,7 +560,6 @@ public class EthernetNetworkFactory extends NetworkFactory {
|
|||||||
+ "hwAddress: " + mHwAddress + ", "
|
+ "hwAddress: " + mHwAddress + ", "
|
||||||
+ "networkCapabilities: " + mCapabilities + ", "
|
+ "networkCapabilities: " + mCapabilities + ", "
|
||||||
+ "networkAgent: " + mNetworkAgent + ", "
|
+ "networkAgent: " + mNetworkAgent + ", "
|
||||||
+ "score: " + getNetworkScore() + ", "
|
|
||||||
+ "ipClient: " + mIpClient + ","
|
+ "ipClient: " + mIpClient + ","
|
||||||
+ "linkProperties: " + mLinkProperties
|
+ "linkProperties: " + mLinkProperties
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.ArgumentMatchers.same;
|
import static org.mockito.ArgumentMatchers.same;
|
||||||
@@ -90,14 +89,13 @@ public class EthernetNetworkFactoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupNetworkAgentMock() {
|
private void setupNetworkAgentMock() {
|
||||||
when(mDeps.makeEthernetNetworkAgent(any(), any(), any(), any(), anyInt(), any(), any(),
|
when(mDeps.makeEthernetNetworkAgent(any(), any(), any(), any(), any(), any(), any()))
|
||||||
any())).thenAnswer(new AnswerWithArguments() {
|
.thenAnswer(new AnswerWithArguments() {
|
||||||
public EthernetNetworkAgent answer(
|
public EthernetNetworkAgent answer(
|
||||||
Context context,
|
Context context,
|
||||||
Looper looper,
|
Looper looper,
|
||||||
NetworkCapabilities nc,
|
NetworkCapabilities nc,
|
||||||
LinkProperties lp,
|
LinkProperties lp,
|
||||||
int networkScore,
|
|
||||||
NetworkAgentConfig config,
|
NetworkAgentConfig config,
|
||||||
NetworkProvider provider,
|
NetworkProvider provider,
|
||||||
EthernetNetworkAgent.Callbacks cb) {
|
EthernetNetworkAgent.Callbacks cb) {
|
||||||
@@ -190,8 +188,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
// provisioning succeeded, verify that the network agent is created, registered, and marked
|
// provisioning succeeded, verify that the network agent is created, registered, and marked
|
||||||
// as connected.
|
// as connected.
|
||||||
verify(mDeps).makeEthernetNetworkAgent(any(), any(), any(), any(), anyInt(), any(), any(),
|
verify(mDeps).makeEthernetNetworkAgent(any(), any(), any(), any(), any(), any(), any());
|
||||||
any());
|
|
||||||
verify(mNetworkAgent).register();
|
verify(mNetworkAgent).register();
|
||||||
verify(mNetworkAgent).markConnected();
|
verify(mNetworkAgent).markConnected();
|
||||||
clearInvocations(mDeps);
|
clearInvocations(mDeps);
|
||||||
@@ -256,8 +253,8 @@ public class EthernetNetworkFactoryTest {
|
|||||||
assertTrue(mNetFactory.updateInterfaceLinkState(iface, false));
|
assertTrue(mNetFactory.updateInterfaceLinkState(iface, false));
|
||||||
// There should not be an active IPClient or NetworkAgent.
|
// There should not be an active IPClient or NetworkAgent.
|
||||||
verify(mDeps, never()).makeIpClient(any(), any(), any());
|
verify(mDeps, never()).makeIpClient(any(), any(), any());
|
||||||
verify(mDeps, never()).makeEthernetNetworkAgent(any(), any(), any(), any(), anyInt(), any(),
|
verify(mDeps, never())
|
||||||
any(), any());
|
.makeEthernetNetworkAgent(any(), any(), any(), any(), any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -382,8 +379,7 @@ public class EthernetNetworkFactoryTest {
|
|||||||
|
|
||||||
mIpClientCallbacks.onProvisioningSuccess(new LinkProperties());
|
mIpClientCallbacks.onProvisioningSuccess(new LinkProperties());
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mDeps).makeEthernetNetworkAgent(any(), any(), any(), any(), anyInt(), any(), any(),
|
verify(mDeps).makeEthernetNetworkAgent(any(), any(), any(), any(), any(), any(), any());
|
||||||
any());
|
|
||||||
|
|
||||||
// verify that unwanted is ignored
|
// verify that unwanted is ignored
|
||||||
clearInvocations(mIpClient);
|
clearInvocations(mIpClient);
|
||||||
|
|||||||
Reference in New Issue
Block a user