Reapply "Add LocalNetworkConfig"
This reverts commit 6eea22b18cace5ab7515ad21c2c019605720907d.
Change-Id: I0a2cef4ee992577674c92ecd384dc6f4361afa02
diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index 0ee3b33..6ce6fcf 100755
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -161,6 +161,7 @@
import android.net.IpMemoryStore;
import android.net.IpPrefix;
import android.net.LinkProperties;
+import android.net.LocalNetworkConfig;
import android.net.MatchAllNetworkSpecifier;
import android.net.NativeNetworkConfig;
import android.net.NativeNetworkType;
@@ -1784,7 +1785,7 @@
mNoServiceNetwork = new NetworkAgentInfo(null,
new Network(INetd.UNREACHABLE_NET_ID),
new NetworkInfo(TYPE_NONE, 0, "", ""),
- new LinkProperties(), new NetworkCapabilities(),
+ new LinkProperties(), new NetworkCapabilities(), null /* localNetworkConfig */,
new NetworkScore.Builder().setLegacyInt(0).build(), mContext, null,
new NetworkAgentConfig(), this, null, null, 0, INVALID_UID,
mLingerDelayMs, mQosCallbackTracker, mDeps);
@@ -4132,6 +4133,11 @@
updateNetworkInfo(nai, info);
break;
}
+ case NetworkAgent.EVENT_LOCAL_NETWORK_CONFIG_CHANGED: {
+ final LocalNetworkConfig config = (LocalNetworkConfig) arg.second;
+ updateLocalNetworkConfig(nai, config);
+ break;
+ }
case NetworkAgent.EVENT_NETWORK_SCORE_CHANGED: {
updateNetworkScore(nai, (NetworkScore) arg.second);
break;
@@ -8093,13 +8099,18 @@
* @param networkCapabilities the initial capabilites of this network. They can be updated
* later : see {@link #updateCapabilities}.
* @param initialScore the initial score of the network. See {@link NetworkAgentInfo#getScore}.
+ * @param localNetworkConfig config about this local network, or null if not a local network
* @param networkAgentConfig metadata about the network. This is never updated.
* @param providerId the ID of the provider owning this NetworkAgent.
* @return the network created for this agent.
*/
- public Network registerNetworkAgent(INetworkAgent na, NetworkInfo networkInfo,
- LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
- @NonNull NetworkScore initialScore, NetworkAgentConfig networkAgentConfig,
+ public Network registerNetworkAgent(INetworkAgent na,
+ NetworkInfo networkInfo,
+ LinkProperties linkProperties,
+ NetworkCapabilities networkCapabilities,
+ @NonNull NetworkScore initialScore,
+ @Nullable LocalNetworkConfig localNetworkConfig,
+ NetworkAgentConfig networkAgentConfig,
int providerId) {
Objects.requireNonNull(networkInfo, "networkInfo must not be null");
Objects.requireNonNull(linkProperties, "linkProperties must not be null");
@@ -8117,12 +8128,20 @@
// Before U, netd doesn't support PHYSICAL_LOCAL networks so this can't work.
throw new IllegalArgumentException("Local agents are not supported in this version");
}
+ final boolean hasLocalNetworkConfig = null != localNetworkConfig;
+ if (hasLocalCap != hasLocalNetworkConfig) {
+ throw new IllegalArgumentException(null != localNetworkConfig
+ ? "Only local network agents can have a LocalNetworkConfig"
+ : "Local network agents must have a LocalNetworkConfig"
+ );
+ }
final int uid = mDeps.getCallingUid();
final long token = Binder.clearCallingIdentity();
try {
return registerNetworkAgentInternal(na, networkInfo, linkProperties,
- networkCapabilities, initialScore, networkAgentConfig, providerId, uid);
+ networkCapabilities, initialScore, networkAgentConfig, localNetworkConfig,
+ providerId, uid);
} finally {
Binder.restoreCallingIdentity(token);
}
@@ -8130,7 +8149,8 @@
private Network registerNetworkAgentInternal(INetworkAgent na, NetworkInfo networkInfo,
LinkProperties linkProperties, NetworkCapabilities networkCapabilities,
- NetworkScore currentScore, NetworkAgentConfig networkAgentConfig, int providerId,
+ NetworkScore currentScore, NetworkAgentConfig networkAgentConfig,
+ @Nullable LocalNetworkConfig localNetworkConfig, int providerId,
int uid) {
// Make a copy of the passed NI, LP, NC as the caller may hold a reference to them
@@ -8138,6 +8158,7 @@
final NetworkInfo niCopy = new NetworkInfo(networkInfo);
final NetworkCapabilities ncCopy = new NetworkCapabilities(networkCapabilities);
final LinkProperties lpCopy = new LinkProperties(linkProperties);
+ // No need to copy |localNetworkConfiguration| as it is immutable.
// At this point the capabilities/properties are untrusted and unverified, e.g. checks that
// the capabilities' access UIDs comply with security limitations. They will be sanitized
@@ -8145,9 +8166,9 @@
// because some of the checks must happen on the handler thread.
final NetworkAgentInfo nai = new NetworkAgentInfo(na,
new Network(mNetIdManager.reserveNetId()), niCopy, lpCopy, ncCopy,
- currentScore, mContext, mTrackerHandler, new NetworkAgentConfig(networkAgentConfig),
- this, mNetd, mDnsResolver, providerId, uid, mLingerDelayMs,
- mQosCallbackTracker, mDeps);
+ localNetworkConfig, currentScore, mContext, mTrackerHandler,
+ new NetworkAgentConfig(networkAgentConfig), this, mNetd, mDnsResolver, providerId,
+ uid, mLingerDelayMs, mQosCallbackTracker, mDeps);
final String extraInfo = niCopy.getExtraInfo();
final String name = TextUtils.isEmpty(extraInfo)
@@ -8882,6 +8903,16 @@
updateCapabilities(nai.getScore(), nai, nai.networkCapabilities);
}
+ private void updateLocalNetworkConfig(@NonNull final NetworkAgentInfo nai,
+ @NonNull final LocalNetworkConfig config) {
+ if (!nai.networkCapabilities.hasCapability(NET_CAPABILITY_LOCAL_NETWORK)) {
+ Log.wtf(TAG, "Ignoring update of a local network info on non-local network " + nai);
+ return;
+ }
+ // TODO : actually apply the diff.
+ nai.localNetworkConfig = config;
+ }
+
/**
* Returns the interface which requires VPN isolation (ingress interface filtering).
*
diff --git a/service/src/com/android/server/connectivity/NetworkAgentInfo.java b/service/src/com/android/server/connectivity/NetworkAgentInfo.java
index 8d0d711..b0ad978 100644
--- a/service/src/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/service/src/com/android/server/connectivity/NetworkAgentInfo.java
@@ -35,6 +35,7 @@
import android.net.INetworkAgentRegistry;
import android.net.INetworkMonitor;
import android.net.LinkProperties;
+import android.net.LocalNetworkConfig;
import android.net.NattKeepalivePacketData;
import android.net.Network;
import android.net.NetworkAgent;
@@ -173,6 +174,7 @@
// TODO: make this private with a getter.
@NonNull public NetworkCapabilities networkCapabilities;
@NonNull public final NetworkAgentConfig networkAgentConfig;
+ @Nullable public LocalNetworkConfig localNetworkConfig;
// Underlying networks declared by the agent.
// The networks in this list might be declared by a VPN using setUnderlyingNetworks and are
@@ -609,6 +611,7 @@
public NetworkAgentInfo(INetworkAgent na, Network net, NetworkInfo info,
@NonNull LinkProperties lp, @NonNull NetworkCapabilities nc,
+ @Nullable LocalNetworkConfig localNetworkConfig,
@NonNull NetworkScore score, Context context,
Handler handler, NetworkAgentConfig config, ConnectivityService connService, INetd netd,
IDnsResolver dnsResolver, int factorySerialNumber, int creatorUid,
@@ -626,6 +629,7 @@
networkInfo = info;
linkProperties = lp;
networkCapabilities = nc;
+ this.localNetworkConfig = localNetworkConfig;
networkAgentConfig = config;
mConnService = connService;
mConnServiceDeps = deps;
@@ -905,6 +909,12 @@
}
@Override
+ public void sendLocalNetworkConfig(@NonNull final LocalNetworkConfig config) {
+ mHandler.obtainMessage(NetworkAgent.EVENT_LOCAL_NETWORK_CONFIG_CHANGED,
+ new Pair<>(NetworkAgentInfo.this, config)).sendToTarget();
+ }
+
+ @Override
public void sendScore(@NonNull final NetworkScore score) {
mHandler.obtainMessage(NetworkAgent.EVENT_NETWORK_SCORE_CHANGED,
new Pair<>(NetworkAgentInfo.this, score)).sendToTarget();