Rename NetworkMisc to NetworkAgentConfig.

NetworkMisc is not really an appropriate name for a system API.

Bug: 138306002
Test: builds, boots, wifi works, telephony works
Test: atest FrameworksNetTests FrameworksWifiTests FrameworksTelephonyTests
Change-Id: I621cfbe165996c67b201ca2dd2f95a5ab9af10ee
Merged-In: I621cfbe165996c67b201ca2dd2f95a5ab9af10ee
This commit is contained in:
Lorenzo Colitti
2020-01-12 22:28:37 +09:00
committed by Chiachang Wang
parent cbd8f2a7a3
commit ab2fed7241
10 changed files with 95 additions and 85 deletions

View File

@@ -3173,8 +3173,8 @@ public class ConnectivityManager {
*/ */
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp, public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
NetworkCapabilities nc, int score, NetworkMisc misc) { NetworkCapabilities nc, int score, NetworkAgentConfig config) {
return registerNetworkAgent(messenger, ni, lp, nc, score, misc, NetworkProvider.ID_NONE); return registerNetworkAgent(messenger, ni, lp, nc, score, config, NetworkProvider.ID_NONE);
} }
/** /**
@@ -3184,9 +3184,10 @@ public class ConnectivityManager {
*/ */
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp, public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
NetworkCapabilities nc, int score, NetworkMisc misc, int providerId) { NetworkCapabilities nc, int score, NetworkAgentConfig config, int providerId) {
try { try {
return mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc, providerId); return mService.registerNetworkAgent(messenger, ni, lp, nc, score, config, providerId);
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }

View File

@@ -20,9 +20,9 @@ import android.app.PendingIntent;
import android.net.ConnectionInfo; import android.net.ConnectionInfo;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.net.Network; import android.net.Network;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkQuotaInfo; import android.net.NetworkQuotaInfo;
import android.net.NetworkRequest; import android.net.NetworkRequest;
import android.net.NetworkState; import android.net.NetworkState;
@@ -153,7 +153,8 @@ interface IConnectivityManager
void declareNetworkRequestUnfulfillable(in NetworkRequest request); void declareNetworkRequestUnfulfillable(in NetworkRequest request);
Network registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp, Network registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
in NetworkCapabilities nc, int score, in NetworkMisc misc, in int factorySerialNumber); in NetworkCapabilities nc, int score, in NetworkAgentConfig config,
in int factorySerialNumber);
NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities, NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
in Messenger messenger, int timeoutSec, in IBinder binder, int legacy); in Messenger messenger, int timeoutSec, in IBinder binder, int legacy);

View File

@@ -221,8 +221,8 @@ public abstract class NetworkAgent {
this(looper, context, logTag, ni, nc, lp, score, null, NetworkProvider.ID_NONE); this(looper, context, logTag, ni, nc, lp, score, null, NetworkProvider.ID_NONE);
} }
public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc) { NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config) {
this(looper, context, logTag, ni, nc, lp, score, misc, NetworkProvider.ID_NONE); this(looper, context, logTag, ni, nc, lp, score, config, NetworkProvider.ID_NONE);
} }
public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
@@ -231,7 +231,7 @@ public abstract class NetworkAgent {
} }
public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc, NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config,
int providerId) { int providerId) {
mHandler = new NetworkAgentHandler(looper); mHandler = new NetworkAgentHandler(looper);
LOG_TAG = logTag; LOG_TAG = logTag;
@@ -245,7 +245,7 @@ public abstract class NetworkAgent {
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService( ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
Context.CONNECTIVITY_SERVICE); Context.CONNECTIVITY_SERVICE);
network = cm.registerNetworkAgent(new Messenger(mHandler), new NetworkInfo(ni), network = cm.registerNetworkAgent(new Messenger(mHandler), new NetworkInfo(ni),
new LinkProperties(lp), new NetworkCapabilities(nc), score, misc, new LinkProperties(lp), new NetworkCapabilities(nc), score, config,
providerId); providerId);
} }

View File

@@ -16,6 +16,8 @@
package android.net; package android.net;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -26,7 +28,7 @@ import android.os.Parcelable;
* *
* @hide * @hide
*/ */
public class NetworkMisc implements Parcelable { public class NetworkAgentConfig implements Parcelable {
/** /**
* If the {@link Network} is a VPN, whether apps are allowed to bypass the * If the {@link Network} is a VPN, whether apps are allowed to bypass the
@@ -83,17 +85,17 @@ public class NetworkMisc implements Parcelable {
*/ */
public boolean hasShownBroken; public boolean hasShownBroken;
public NetworkMisc() { public NetworkAgentConfig() {
} }
public NetworkMisc(NetworkMisc nm) { public NetworkAgentConfig(@Nullable NetworkAgentConfig nac) {
if (nm != null) { if (nac != null) {
allowBypass = nm.allowBypass; allowBypass = nac.allowBypass;
explicitlySelected = nm.explicitlySelected; explicitlySelected = nac.explicitlySelected;
acceptUnvalidated = nm.acceptUnvalidated; acceptUnvalidated = nac.acceptUnvalidated;
subscriberId = nm.subscriberId; subscriberId = nac.subscriberId;
provisioningNotificationDisabled = nm.provisioningNotificationDisabled; provisioningNotificationDisabled = nac.provisioningNotificationDisabled;
skip464xlat = nm.skip464xlat; skip464xlat = nac.skip464xlat;
} }
} }
@@ -112,22 +114,23 @@ public class NetworkMisc implements Parcelable {
out.writeInt(skip464xlat ? 1 : 0); out.writeInt(skip464xlat ? 1 : 0);
} }
public static final @android.annotation.NonNull Creator<NetworkMisc> CREATOR = new Creator<NetworkMisc>() { public static final @NonNull Creator<NetworkAgentConfig> CREATOR =
new Creator<NetworkAgentConfig>() {
@Override @Override
public NetworkMisc createFromParcel(Parcel in) { public NetworkAgentConfig createFromParcel(Parcel in) {
NetworkMisc networkMisc = new NetworkMisc(); NetworkAgentConfig networkAgentConfig = new NetworkAgentConfig();
networkMisc.allowBypass = in.readInt() != 0; networkAgentConfig.allowBypass = in.readInt() != 0;
networkMisc.explicitlySelected = in.readInt() != 0; networkAgentConfig.explicitlySelected = in.readInt() != 0;
networkMisc.acceptUnvalidated = in.readInt() != 0; networkAgentConfig.acceptUnvalidated = in.readInt() != 0;
networkMisc.subscriberId = in.readString(); networkAgentConfig.subscriberId = in.readString();
networkMisc.provisioningNotificationDisabled = in.readInt() != 0; networkAgentConfig.provisioningNotificationDisabled = in.readInt() != 0;
networkMisc.skip464xlat = in.readInt() != 0; networkAgentConfig.skip464xlat = in.readInt() != 0;
return networkMisc; return networkAgentConfig;
} }
@Override @Override
public NetworkMisc[] newArray(int size) { public NetworkAgentConfig[] newArray(int size) {
return new NetworkMisc[size]; return new NetworkAgentConfig[size];
} }
}; };
} }

View File

@@ -86,11 +86,11 @@ import android.net.MatchAllNetworkSpecifier;
import android.net.NattSocketKeepalive; import android.net.NattSocketKeepalive;
import android.net.Network; import android.net.Network;
import android.net.NetworkAgent; import android.net.NetworkAgent;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkConfig; import android.net.NetworkConfig;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.DetailedState;
import android.net.NetworkMisc;
import android.net.NetworkMonitorManager; import android.net.NetworkMonitorManager;
import android.net.NetworkPolicyManager; import android.net.NetworkPolicyManager;
import android.net.NetworkProvider; import android.net.NetworkProvider;
@@ -2623,8 +2623,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (nai.everConnected) { if (nai.everConnected) {
loge("ERROR: cannot call explicitlySelected on already-connected network"); loge("ERROR: cannot call explicitlySelected on already-connected network");
} }
nai.networkMisc.explicitlySelected = toBool(msg.arg1); nai.networkAgentConfig.explicitlySelected = toBool(msg.arg1);
nai.networkMisc.acceptUnvalidated = toBool(msg.arg1) && toBool(msg.arg2); nai.networkAgentConfig.acceptUnvalidated = toBool(msg.arg1) && toBool(msg.arg2);
// Mark the network as temporarily accepting partial connectivity so that it // Mark the network as temporarily accepting partial connectivity so that it
// will be validated (and possibly become default) even if it only provides // will be validated (and possibly become default) even if it only provides
// partial internet access. Note that if user connects to partial connectivity // partial internet access. Note that if user connects to partial connectivity
@@ -2632,7 +2632,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// out of wifi coverage) and if the same wifi is available again, the device // out of wifi coverage) and if the same wifi is available again, the device
// will auto connect to this wifi even though the wifi has "no internet". // will auto connect to this wifi even though the wifi has "no internet".
// TODO: Evaluate using a separate setting in IpMemoryStore. // TODO: Evaluate using a separate setting in IpMemoryStore.
nai.networkMisc.acceptPartialConnectivity = toBool(msg.arg2); nai.networkAgentConfig.acceptPartialConnectivity = toBool(msg.arg2);
break; break;
} }
case NetworkAgent.EVENT_SOCKET_KEEPALIVE: { case NetworkAgent.EVENT_SOCKET_KEEPALIVE: {
@@ -2664,10 +2664,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
// Only show the notification when the private DNS is broken and the // Only show the notification when the private DNS is broken and the
// PRIVATE_DNS_BROKEN notification hasn't shown since last valid. // PRIVATE_DNS_BROKEN notification hasn't shown since last valid.
if (privateDnsBroken && !nai.networkMisc.hasShownBroken) { if (privateDnsBroken && !nai.networkAgentConfig.hasShownBroken) {
showNetworkNotification(nai, NotificationType.PRIVATE_DNS_BROKEN); showNetworkNotification(nai, NotificationType.PRIVATE_DNS_BROKEN);
} }
nai.networkMisc.hasShownBroken = privateDnsBroken; nai.networkAgentConfig.hasShownBroken = privateDnsBroken;
} else if (nai.networkCapabilities.isPrivateDnsBroken()) { } else if (nai.networkCapabilities.isPrivateDnsBroken()) {
// If probePrivateDnsCompleted is false but nai.networkCapabilities says // If probePrivateDnsCompleted is false but nai.networkCapabilities says
// private DNS is broken, it means this network is being reevaluated. // private DNS is broken, it means this network is being reevaluated.
@@ -2677,7 +2677,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
nai.networkCapabilities.setPrivateDnsBroken(false); nai.networkCapabilities.setPrivateDnsBroken(false);
final int oldScore = nai.getCurrentScore(); final int oldScore = nai.getCurrentScore();
updateCapabilities(oldScore, nai, nai.networkCapabilities); updateCapabilities(oldScore, nai, nai.networkCapabilities);
nai.networkMisc.hasShownBroken = false; nai.networkAgentConfig.hasShownBroken = false;
} }
break; break;
} }
@@ -2736,7 +2736,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// If network becomes valid, the hasShownBroken should be reset for // If network becomes valid, the hasShownBroken should be reset for
// that network so that the notification will be fired when the private // that network so that the notification will be fired when the private
// DNS is broken again. // DNS is broken again.
nai.networkMisc.hasShownBroken = false; nai.networkAgentConfig.hasShownBroken = false;
} }
} else if (partialConnectivityChanged) { } else if (partialConnectivityChanged) {
updateCapabilities(nai.getCurrentScore(), nai, nai.networkCapabilities); updateCapabilities(nai.getCurrentScore(), nai, nai.networkCapabilities);
@@ -2795,9 +2795,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
loge("EVENT_PROVISIONING_NOTIFICATION from unknown NetworkMonitor"); loge("EVENT_PROVISIONING_NOTIFICATION from unknown NetworkMonitor");
break; break;
} }
if (!nai.networkMisc.provisioningNotificationDisabled) { if (!nai.networkAgentConfig.provisioningNotificationDisabled) {
mNotifier.showNotification(netId, NotificationType.SIGN_IN, nai, null, mNotifier.showNotification(netId, NotificationType.SIGN_IN, nai, null,
(PendingIntent) msg.obj, nai.networkMisc.explicitlySelected); (PendingIntent) msg.obj,
nai.networkAgentConfig.explicitlySelected);
} }
} }
break; break;
@@ -3147,8 +3148,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
// This should never fail. Specifying an already in use NetID will cause failure. // This should never fail. Specifying an already in use NetID will cause failure.
if (networkAgent.isVPN()) { if (networkAgent.isVPN()) {
mNetd.networkCreateVpn(networkAgent.network.netId, mNetd.networkCreateVpn(networkAgent.network.netId,
(networkAgent.networkMisc == null (networkAgent.networkAgentConfig == null
|| !networkAgent.networkMisc.allowBypass)); || !networkAgent.networkAgentConfig.allowBypass));
} else { } else {
mNetd.networkCreatePhysical(networkAgent.network.netId, mNetd.networkCreatePhysical(networkAgent.network.netId,
getNetworkPermission(networkAgent.networkCapabilities)); getNetworkPermission(networkAgent.networkCapabilities));
@@ -3448,16 +3449,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
return; return;
} }
if (!nai.networkMisc.explicitlySelected) { if (!nai.networkAgentConfig.explicitlySelected) {
Slog.wtf(TAG, "BUG: setAcceptUnvalidated non non-explicitly selected network"); Slog.wtf(TAG, "BUG: setAcceptUnvalidated non non-explicitly selected network");
} }
if (accept != nai.networkMisc.acceptUnvalidated) { if (accept != nai.networkAgentConfig.acceptUnvalidated) {
nai.networkMisc.acceptUnvalidated = accept; nai.networkAgentConfig.acceptUnvalidated = accept;
// If network becomes partial connectivity and user already accepted to use this // If network becomes partial connectivity and user already accepted to use this
// network, we should respect the user's option and don't need to popup the // network, we should respect the user's option and don't need to popup the
// PARTIAL_CONNECTIVITY notification to user again. // PARTIAL_CONNECTIVITY notification to user again.
nai.networkMisc.acceptPartialConnectivity = accept; nai.networkAgentConfig.acceptPartialConnectivity = accept;
rematchAllNetworksAndRequests(); rematchAllNetworksAndRequests();
sendUpdatedScoreToFactories(nai); sendUpdatedScoreToFactories(nai);
} }
@@ -3494,8 +3495,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
return; return;
} }
if (accept != nai.networkMisc.acceptPartialConnectivity) { if (accept != nai.networkAgentConfig.acceptPartialConnectivity) {
nai.networkMisc.acceptPartialConnectivity = accept; nai.networkAgentConfig.acceptPartialConnectivity = accept;
} }
// TODO: Use the current design or save the user choice into IpMemoryStore. // TODO: Use the current design or save the user choice into IpMemoryStore.
@@ -3720,7 +3721,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
action = ConnectivityManager.ACTION_PROMPT_PARTIAL_CONNECTIVITY; action = ConnectivityManager.ACTION_PROMPT_PARTIAL_CONNECTIVITY;
// Don't bother the user with a high-priority notification if the network was not // Don't bother the user with a high-priority notification if the network was not
// explicitly selected by the user. // explicitly selected by the user.
highPriority = nai.networkMisc.explicitlySelected; highPriority = nai.networkAgentConfig.explicitlySelected;
break; break;
default: default:
Slog.wtf(TAG, "Unknown notification type " + type); Slog.wtf(TAG, "Unknown notification type " + type);
@@ -3753,14 +3754,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
// automatically connects to a network that has partial Internet access, the user will // automatically connects to a network that has partial Internet access, the user will
// always be able to use it, either because they've already chosen "don't ask again" or // always be able to use it, either because they've already chosen "don't ask again" or
// because we have prompt them. // because we have prompt them.
if (nai.partialConnectivity && !nai.networkMisc.acceptPartialConnectivity) { if (nai.partialConnectivity && !nai.networkAgentConfig.acceptPartialConnectivity) {
return true; return true;
} }
// If a network has no Internet access, only prompt if the network was explicitly selected // If a network has no Internet access, only prompt if the network was explicitly selected
// and if the user has not already told us to use the network regardless of whether it // and if the user has not already told us to use the network regardless of whether it
// validated or not. // validated or not.
if (nai.networkMisc.explicitlySelected && !nai.networkMisc.acceptUnvalidated) { if (nai.networkAgentConfig.explicitlySelected
&& !nai.networkAgentConfig.acceptUnvalidated) {
return true; return true;
} }
@@ -5485,9 +5487,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
*/ */
public Network registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo, public Network registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,
LinkProperties linkProperties, NetworkCapabilities networkCapabilities, LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
int currentScore, NetworkMisc networkMisc) { int currentScore, NetworkAgentConfig networkAgentConfig) {
return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities, return registerNetworkAgent(messenger, networkInfo, linkProperties, networkCapabilities,
currentScore, networkMisc, NetworkProvider.ID_NONE); currentScore, networkAgentConfig, NetworkProvider.ID_NONE);
} }
/** /**
@@ -5502,13 +5504,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
* later : see {@link #updateCapabilities}. * later : see {@link #updateCapabilities}.
* @param currentScore the initial score of the network. See * @param currentScore the initial score of the network. See
* {@link NetworkAgentInfo#getCurrentScore}. * {@link NetworkAgentInfo#getCurrentScore}.
* @param networkMisc metadata about the network. This is never updated. * @param networkAgentConfig metadata about the network. This is never updated.
* @param providerId the ID of the provider owning this NetworkAgent. * @param providerId the ID of the provider owning this NetworkAgent.
* @return the network created for this agent. * @return the network created for this agent.
*/ */
public Network registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo, public Network registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo,
LinkProperties linkProperties, NetworkCapabilities networkCapabilities, LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
int currentScore, NetworkMisc networkMisc, int providerId) { int currentScore, NetworkAgentConfig networkAgentConfig, int providerId) {
enforceNetworkFactoryPermission(); enforceNetworkFactoryPermission();
LinkProperties lp = new LinkProperties(linkProperties); LinkProperties lp = new LinkProperties(linkProperties);
@@ -5520,8 +5522,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
ns.putIntExtension(NetworkScore.LEGACY_SCORE, currentScore); ns.putIntExtension(NetworkScore.LEGACY_SCORE, currentScore);
final NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(), final NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(),
new Network(mNetIdManager.reserveNetId()), new NetworkInfo(networkInfo), lp, nc, new Network(mNetIdManager.reserveNetId()), new NetworkInfo(networkInfo), lp, nc,
ns, mContext, mTrackerHandler, new NetworkMisc(networkMisc), this, mNetd, ns, mContext, mTrackerHandler, new NetworkAgentConfig(networkAgentConfig), this,
mDnsResolver, mNMS, providerId); mNetd, mDnsResolver, mNMS, providerId);
// Make sure the network capabilities reflect what the agent info says. // Make sure the network capabilities reflect what the agent info says.
nai.getAndSetNetworkCapabilities(mixInCapabilities(nai, nc)); nai.getAndSetNetworkCapabilities(mixInCapabilities(nai, nc));
final String extraInfo = networkInfo.getExtraInfo(); final String extraInfo = networkInfo.getExtraInfo();
@@ -5942,7 +5944,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
LinkProperties lp) { LinkProperties lp) {
if (nc == null || lp == null) return false; if (nc == null || lp == null) return false;
return nai.isVPN() return nai.isVPN()
&& !nai.networkMisc.allowBypass && !nai.networkAgentConfig.allowBypass
&& nc.getEstablishingVpnAppUid() != Process.SYSTEM_UID && nc.getEstablishingVpnAppUid() != Process.SYSTEM_UID
&& lp.getInterfaceName() != null && lp.getInterfaceName() != null
&& (lp.hasIPv4DefaultRoute() || lp.hasIPv6DefaultRoute()); && (lp.hasIPv4DefaultRoute() || lp.hasIPv6DefaultRoute());
@@ -6633,7 +6635,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// command must be sent after updating LinkProperties to maximize chances of // command must be sent after updating LinkProperties to maximize chances of
// NetworkMonitor seeing the correct LinkProperties when starting. // NetworkMonitor seeing the correct LinkProperties when starting.
// TODO: pass LinkProperties to the NetworkMonitor in the notifyNetworkConnected call. // TODO: pass LinkProperties to the NetworkMonitor in the notifyNetworkConnected call.
if (networkAgent.networkMisc.acceptPartialConnectivity) { if (networkAgent.networkAgentConfig.acceptPartialConnectivity) {
networkAgent.networkMonitor().setAcceptPartialConnectivity(); networkAgent.networkMonitor().setAcceptPartialConnectivity();
} }
networkAgent.networkMonitor().notifyNetworkConnected( networkAgent.networkMonitor().notifyNetworkConnected(

View File

@@ -116,7 +116,8 @@ public class Nat464Xlat extends BaseNetworkObserver {
&& !lp.hasIpv4Address(); && !lp.hasIpv4Address();
// If the network tells us it doesn't use clat, respect that. // If the network tells us it doesn't use clat, respect that.
final boolean skip464xlat = (nai.netMisc() != null) && nai.netMisc().skip464xlat; final boolean skip464xlat = (nai.netAgentConfig() != null)
&& nai.netAgentConfig().skip464xlat;
return supported && connected && isIpv6OnlyNetwork && !skip464xlat; return supported && connected && isIpv6OnlyNetwork && !skip464xlat;
} }

View File

@@ -23,9 +23,9 @@ import android.net.INetd;
import android.net.INetworkMonitor; import android.net.INetworkMonitor;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.net.Network; import android.net.Network;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkMonitorManager; import android.net.NetworkMonitorManager;
import android.net.NetworkRequest; import android.net.NetworkRequest;
import android.net.NetworkScore; import android.net.NetworkScore;
@@ -127,7 +127,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
// This should only be modified by ConnectivityService, via setNetworkCapabilities(). // This should only be modified by ConnectivityService, via setNetworkCapabilities().
// TODO: make this private with a getter. // TODO: make this private with a getter.
public NetworkCapabilities networkCapabilities; public NetworkCapabilities networkCapabilities;
public final NetworkMisc networkMisc; public final NetworkAgentConfig networkAgentConfig;
// Indicates if netd has been told to create this Network. From this point on the appropriate // Indicates if netd has been told to create this Network. From this point on the appropriate
// routing rules are setup and routes are added so packets can begin flowing over the Network. // routing rules are setup and routes are added so packets can begin flowing over the Network.
// This is a sticky bit; once set it is never cleared. // This is a sticky bit; once set it is never cleared.
@@ -261,7 +261,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, Network net, NetworkInfo info, public NetworkAgentInfo(Messenger messenger, AsyncChannel ac, Network net, NetworkInfo info,
LinkProperties lp, NetworkCapabilities nc, @NonNull NetworkScore ns, Context context, LinkProperties lp, NetworkCapabilities nc, @NonNull NetworkScore ns, Context context,
Handler handler, NetworkMisc misc, ConnectivityService connService, INetd netd, Handler handler, NetworkAgentConfig config, ConnectivityService connService, INetd netd,
IDnsResolver dnsResolver, INetworkManagementService nms, int factorySerialNumber) { IDnsResolver dnsResolver, INetworkManagementService nms, int factorySerialNumber) {
this.messenger = messenger; this.messenger = messenger;
asyncChannel = ac; asyncChannel = ac;
@@ -274,7 +274,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
mConnService = connService; mConnService = connService;
mContext = context; mContext = context;
mHandler = handler; mHandler = handler;
networkMisc = misc; networkAgentConfig = config;
this.factorySerialNumber = factorySerialNumber; this.factorySerialNumber = factorySerialNumber;
} }
@@ -309,8 +309,8 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
return mConnService; return mConnService;
} }
public NetworkMisc netMisc() { public NetworkAgentConfig netAgentConfig() {
return networkMisc; return networkAgentConfig;
} }
public Handler handler() { public Handler handler() {
@@ -487,7 +487,8 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
// selected and we're trying to see what its score could be. This ensures that we don't tear // selected and we're trying to see what its score could be. This ensures that we don't tear
// down an explicitly selected network before the user gets a chance to prefer it when // down an explicitly selected network before the user gets a chance to prefer it when
// a higher-scoring network (e.g., Ethernet) is available. // a higher-scoring network (e.g., Ethernet) is available.
if (networkMisc.explicitlySelected && (networkMisc.acceptUnvalidated || pretendValidated)) { if (networkAgentConfig.explicitlySelected
&& (networkAgentConfig.acceptUnvalidated || pretendValidated)) {
return ConnectivityConstants.EXPLICITLY_SELECTED_NETWORK_SCORE; return ConnectivityConstants.EXPLICITLY_SELECTED_NETWORK_SCORE;
} }
@@ -533,7 +534,8 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
synchronized (this) { synchronized (this) {
// Network objects are outwardly immutable so there is no point in duplicating. // Network objects are outwardly immutable so there is no point in duplicating.
// Duplicating also precludes sharing socket factories and connection pools. // Duplicating also precludes sharing socket factories and connection pools.
final String subscriberId = (networkMisc != null) ? networkMisc.subscriberId : null; final String subscriberId = (networkAgentConfig != null)
? networkAgentConfig.subscriberId : null;
return new NetworkState(new NetworkInfo(networkInfo), return new NetworkState(new NetworkInfo(networkInfo),
new LinkProperties(linkProperties), new LinkProperties(linkProperties),
new NetworkCapabilities(networkCapabilities), network, subscriberId, null); new NetworkCapabilities(networkCapabilities), network, subscriberId, null);
@@ -641,13 +643,13 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
+ "nc{" + networkCapabilities + "} Score{" + getCurrentScore() + "} " + "nc{" + networkCapabilities + "} Score{" + getCurrentScore() + "} "
+ "everValidated{" + everValidated + "} lastValidated{" + lastValidated + "} " + "everValidated{" + everValidated + "} lastValidated{" + lastValidated + "} "
+ "created{" + created + "} lingering{" + isLingering() + "} " + "created{" + created + "} lingering{" + isLingering() + "} "
+ "explicitlySelected{" + networkMisc.explicitlySelected + "} " + "explicitlySelected{" + networkAgentConfig.explicitlySelected + "} "
+ "acceptUnvalidated{" + networkMisc.acceptUnvalidated + "} " + "acceptUnvalidated{" + networkAgentConfig.acceptUnvalidated + "} "
+ "everCaptivePortalDetected{" + everCaptivePortalDetected + "} " + "everCaptivePortalDetected{" + everCaptivePortalDetected + "} "
+ "lastCaptivePortalDetected{" + lastCaptivePortalDetected + "} " + "lastCaptivePortalDetected{" + lastCaptivePortalDetected + "} "
+ "captivePortalValidationPending{" + captivePortalValidationPending + "} " + "captivePortalValidationPending{" + captivePortalValidationPending + "} "
+ "partialConnectivity{" + partialConnectivity + "} " + "partialConnectivity{" + partialConnectivity + "} "
+ "acceptPartialConnectivity{" + networkMisc.acceptPartialConnectivity + "} " + "acceptPartialConnectivity{" + networkAgentConfig.acceptPartialConnectivity + "} "
+ "clat{" + clatd + "} " + "clat{" + clatd + "} "
+ "}"; + "}";
} }

View File

@@ -35,9 +35,9 @@ import android.net.ConnectivityManager;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.net.Network; import android.net.Network;
import android.net.NetworkAgent; import android.net.NetworkAgent;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkProvider; import android.net.NetworkProvider;
import android.net.NetworkSpecifier; import android.net.NetworkSpecifier;
import android.net.SocketKeepalive; import android.net.SocketKeepalive;
@@ -114,7 +114,7 @@ public class NetworkAgentWrapper implements TestableNetworkCallback.HasNetwork {
public InstrumentedNetworkAgent(NetworkAgentWrapper wrapper, LinkProperties lp) { public InstrumentedNetworkAgent(NetworkAgentWrapper wrapper, LinkProperties lp) {
super(wrapper.mHandlerThread.getLooper(), wrapper.mContext, wrapper.mLogTag, super(wrapper.mHandlerThread.getLooper(), wrapper.mContext, wrapper.mLogTag,
wrapper.mNetworkInfo, wrapper.mNetworkCapabilities, lp, wrapper.mScore, wrapper.mNetworkInfo, wrapper.mNetworkCapabilities, lp, wrapper.mScore,
new NetworkMisc(), NetworkProvider.ID_NONE); new NetworkAgentConfig(), NetworkProvider.ID_NONE);
mWrapper = wrapper; mWrapper = wrapper;
} }

View File

@@ -35,9 +35,9 @@ import android.net.ConnectivityManager;
import android.net.IDnsResolver; import android.net.IDnsResolver;
import android.net.INetd; import android.net.INetd;
import android.net.Network; import android.net.Network;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkProvider; import android.net.NetworkProvider;
import android.net.NetworkScore; import android.net.NetworkScore;
import android.os.INetworkManagementService; import android.os.INetworkManagementService;
@@ -75,7 +75,7 @@ public class LingerMonitorTest {
@Mock INetd mNetd; @Mock INetd mNetd;
@Mock INetworkManagementService mNMS; @Mock INetworkManagementService mNMS;
@Mock Context mCtx; @Mock Context mCtx;
@Mock NetworkMisc mMisc; @Mock NetworkAgentConfig mAgentConfig;
@Mock NetworkNotificationManager mNotifier; @Mock NetworkNotificationManager mNotifier;
@Mock Resources mResources; @Mock Resources mResources;
@@ -358,7 +358,7 @@ public class LingerMonitorTest {
NetworkScore ns = new NetworkScore(); NetworkScore ns = new NetworkScore();
ns.putIntExtension(NetworkScore.LEGACY_SCORE, 50); ns.putIntExtension(NetworkScore.LEGACY_SCORE, 50);
NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null, NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null,
caps, ns, mCtx, null, mMisc, mConnService, mNetd, mDnsResolver, mNMS, caps, ns, mCtx, null, mAgentConfig, mConnService, mNetd, mDnsResolver, mNMS,
NetworkProvider.ID_NONE); NetworkProvider.ID_NONE);
nai.everValidated = true; nai.everValidated = true;
return nai; return nai;

View File

@@ -33,8 +33,8 @@ import android.net.InterfaceConfiguration;
import android.net.IpPrefix; import android.net.IpPrefix;
import android.net.LinkAddress; import android.net.LinkAddress;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.net.NetworkAgentConfig;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.os.Handler; import android.os.Handler;
import android.os.INetworkManagementService; import android.os.INetworkManagementService;
import android.os.test.TestLooper; import android.os.test.TestLooper;
@@ -63,7 +63,7 @@ public class Nat464XlatTest {
static final int NETID = 42; static final int NETID = 42;
@Mock ConnectivityService mConnectivity; @Mock ConnectivityService mConnectivity;
@Mock NetworkMisc mMisc; @Mock NetworkAgentConfig mAgentConfig;
@Mock IDnsResolver mDnsResolver; @Mock IDnsResolver mDnsResolver;
@Mock INetd mNetd; @Mock INetd mNetd;
@Mock INetworkManagementService mNms; @Mock INetworkManagementService mNms;
@@ -93,7 +93,7 @@ public class Nat464XlatTest {
mNai.networkInfo = new NetworkInfo(null); mNai.networkInfo = new NetworkInfo(null);
mNai.networkInfo.setType(ConnectivityManager.TYPE_WIFI); mNai.networkInfo.setType(ConnectivityManager.TYPE_WIFI);
when(mNai.connService()).thenReturn(mConnectivity); when(mNai.connService()).thenReturn(mConnectivity);
when(mNai.netMisc()).thenReturn(mMisc); when(mNai.netAgentConfig()).thenReturn(mAgentConfig);
when(mNai.handler()).thenReturn(mHandler); when(mNai.handler()).thenReturn(mHandler);
when(mNms.getInterfaceConfig(eq(STACKED_IFACE))).thenReturn(mConfig); when(mNms.getInterfaceConfig(eq(STACKED_IFACE))).thenReturn(mConfig);
@@ -104,7 +104,7 @@ public class Nat464XlatTest {
String msg = String.format("requiresClat expected %b for type=%d state=%s skip=%b " String msg = String.format("requiresClat expected %b for type=%d state=%s skip=%b "
+ "nat64Prefix=%s addresses=%s", expected, nai.networkInfo.getType(), + "nat64Prefix=%s addresses=%s", expected, nai.networkInfo.getType(),
nai.networkInfo.getDetailedState(), nai.networkInfo.getDetailedState(),
mMisc.skip464xlat, nai.linkProperties.getNat64Prefix(), mAgentConfig.skip464xlat, nai.linkProperties.getNat64Prefix(),
nai.linkProperties.getLinkAddresses()); nai.linkProperties.getLinkAddresses());
assertEquals(msg, expected, Nat464Xlat.requiresClat(nai)); assertEquals(msg, expected, Nat464Xlat.requiresClat(nai));
} }
@@ -113,7 +113,7 @@ public class Nat464XlatTest {
String msg = String.format("shouldStartClat expected %b for type=%d state=%s skip=%b " String msg = String.format("shouldStartClat expected %b for type=%d state=%s skip=%b "
+ "nat64Prefix=%s addresses=%s", expected, nai.networkInfo.getType(), + "nat64Prefix=%s addresses=%s", expected, nai.networkInfo.getType(),
nai.networkInfo.getDetailedState(), nai.networkInfo.getDetailedState(),
mMisc.skip464xlat, nai.linkProperties.getNat64Prefix(), mAgentConfig.skip464xlat, nai.linkProperties.getNat64Prefix(),
nai.linkProperties.getLinkAddresses()); nai.linkProperties.getLinkAddresses());
assertEquals(msg, expected, Nat464Xlat.shouldStartClat(nai)); assertEquals(msg, expected, Nat464Xlat.shouldStartClat(nai));
} }
@@ -151,11 +151,11 @@ public class Nat464XlatTest {
assertRequiresClat(true, mNai); assertRequiresClat(true, mNai);
assertShouldStartClat(true, mNai); assertShouldStartClat(true, mNai);
mMisc.skip464xlat = true; mAgentConfig.skip464xlat = true;
assertRequiresClat(false, mNai); assertRequiresClat(false, mNai);
assertShouldStartClat(false, mNai); assertShouldStartClat(false, mNai);
mMisc.skip464xlat = false; mAgentConfig.skip464xlat = false;
assertRequiresClat(true, mNai); assertRequiresClat(true, mNai);
assertShouldStartClat(true, mNai); assertShouldStartClat(true, mNai);