Remove support for legacy network agents

Test: FrameworksNetTests NetworkStackTests
Bug: 167544279
Change-Id: Ia950e16d991cd08d4b609d71aad61a4a4f7fda39
This commit is contained in:
Chalard Jean
2020-10-09 18:50:08 +09:00
parent 710e1dc25f
commit dcac686b24

View File

@@ -51,7 +51,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* An agent manages the life cycle of a network. A network starts its * An agent manages the life cycle of a network. A network starts its
* life cycle when {@link register} is called on NetworkAgent. The network * life cycle when {@link register} is called on NetworkAgent. The network
* is then connecting. When full L3 connectivity has been established, * is then connecting. When full L3 connectivity has been established,
* the agent shoud call {@link markConnected} to inform the system that * the agent should call {@link markConnected} to inform the system that
* this network is ready to use. When the network disconnects its life * this network is ready to use. When the network disconnects its life
* ends and the agent should call {@link unregister}, at which point the * ends and the agent should call {@link unregister}, at which point the
* system will clean up and free resources. * system will clean up and free resources.
@@ -94,12 +94,6 @@ public abstract class NetworkAgent {
@Nullable @Nullable
private volatile Network mNetwork; private volatile Network mNetwork;
// Whether this NetworkAgent is using the legacy (never unhidden) API. The difference is
// that the legacy API uses NetworkInfo to convey the state, while the current API is
// exposing methods to manage it and generate it internally instead.
// TODO : remove this as soon as all agents have been converted.
private final boolean mIsLegacy;
private final Handler mHandler; private final Handler mHandler;
private volatile AsyncChannel mAsyncChannel; private volatile AsyncChannel mAsyncChannel;
private final String LOG_TAG; private final String LOG_TAG;
@@ -110,8 +104,6 @@ public abstract class NetworkAgent {
private static final long BW_REFRESH_MIN_WIN_MS = 500; private static final long BW_REFRESH_MIN_WIN_MS = 500;
private boolean mBandwidthUpdateScheduled = false; private boolean mBandwidthUpdateScheduled = false;
private AtomicBoolean mBandwidthUpdatePending = new AtomicBoolean(false); private AtomicBoolean mBandwidthUpdatePending = new AtomicBoolean(false);
// Not used by legacy agents. Non-legacy agents use this to convert the NetworkAgent system API
// into the internal API of ConnectivityService.
@NonNull @NonNull
private NetworkInfo mNetworkInfo; private NetworkInfo mNetworkInfo;
@NonNull @NonNull
@@ -364,7 +356,7 @@ public abstract class NetworkAgent {
@NonNull NetworkAgentConfig config, @Nullable NetworkProvider provider) { @NonNull NetworkAgentConfig config, @Nullable NetworkProvider provider) {
this(looper, context, logTag, nc, lp, score, config, this(looper, context, logTag, nc, lp, score, config,
provider == null ? NetworkProvider.ID_NONE : provider.getProviderId(), provider == null ? NetworkProvider.ID_NONE : provider.getProviderId(),
getLegacyNetworkInfo(config), false /* legacy */); getLegacyNetworkInfo(config));
} }
private static class InitialConfiguration { private static class InitialConfiguration {
@@ -389,11 +381,9 @@ public abstract class NetworkAgent {
private NetworkAgent(@NonNull Looper looper, @NonNull Context context, @NonNull String logTag, private NetworkAgent(@NonNull Looper looper, @NonNull Context context, @NonNull String logTag,
@NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, int score, @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, int score,
@NonNull NetworkAgentConfig config, int providerId, @NonNull NetworkInfo ni, @NonNull NetworkAgentConfig config, int providerId, @NonNull NetworkInfo ni) {
boolean legacy) {
mHandler = new NetworkAgentHandler(looper); mHandler = new NetworkAgentHandler(looper);
LOG_TAG = logTag; LOG_TAG = logTag;
mIsLegacy = legacy;
mNetworkInfo = new NetworkInfo(ni); mNetworkInfo = new NetworkInfo(ni);
this.providerId = providerId; this.providerId = providerId;
if (ni == null || nc == null || lp == null) { if (ni == null || nc == null || lp == null) {
@@ -667,11 +657,6 @@ public abstract class NetworkAgent {
* Call {@link #unregister} to disconnect. * Call {@link #unregister} to disconnect.
*/ */
public void markConnected() { public void markConnected() {
if (mIsLegacy) {
throw new UnsupportedOperationException(
"Legacy agents can't call markConnected.");
}
// |reason| cannot be used by the non-legacy agents
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null /* reason */, mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null /* reason */,
mNetworkInfo.getExtraInfo()); mNetworkInfo.getExtraInfo());
queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo); queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo);
@@ -684,9 +669,6 @@ public abstract class NetworkAgent {
* the network is torn down and this agent can no longer be used. * the network is torn down and this agent can no longer be used.
*/ */
public void unregister() { public void unregister() {
if (mIsLegacy) {
throw new UnsupportedOperationException("Legacy agents can't call unregister.");
}
// When unregistering an agent nobody should use the extrainfo (or reason) any more. // When unregistering an agent nobody should use the extrainfo (or reason) any more.
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null /* reason */, mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null /* reason */,
null /* extraInfo */); null /* extraInfo */);
@@ -706,9 +688,6 @@ public abstract class NetworkAgent {
*/ */
@Deprecated @Deprecated
public void setLegacySubtype(final int legacySubtype, @NonNull final String legacySubtypeName) { public void setLegacySubtype(final int legacySubtype, @NonNull final String legacySubtypeName) {
if (mIsLegacy) {
throw new UnsupportedOperationException("Legacy agents can't call setLegacySubtype.");
}
mNetworkInfo.setSubtype(legacySubtype, legacySubtypeName); mNetworkInfo.setSubtype(legacySubtype, legacySubtypeName);
queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo); queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo);
} }
@@ -731,9 +710,6 @@ public abstract class NetworkAgent {
*/ */
@Deprecated @Deprecated
public void setLegacyExtraInfo(@Nullable final String extraInfo) { public void setLegacyExtraInfo(@Nullable final String extraInfo) {
if (mIsLegacy) {
throw new UnsupportedOperationException("Legacy agents can't call setLegacyExtraInfo.");
}
mNetworkInfo.setExtraInfo(extraInfo); mNetworkInfo.setExtraInfo(extraInfo);
queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo); queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo);
} }
@@ -744,9 +720,6 @@ public abstract class NetworkAgent {
*/ */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public final void sendNetworkInfo(NetworkInfo networkInfo) { public final void sendNetworkInfo(NetworkInfo networkInfo) {
if (!mIsLegacy) {
throw new UnsupportedOperationException("Only legacy agents can call sendNetworkInfo.");
}
queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, new NetworkInfo(networkInfo)); queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, new NetworkInfo(networkInfo));
} }