Add LocalNetworkConfig
This doesn't do anything at this patchset, but the whole pipe from the agent to ConnectivityService is built. LocalNetworkInfo will be the name of the public information sent in callbacks to clients. Test: CSLocalAgentTests Change-Id: I70e133031ef3b0aaf6c3e59ccc2ad895c66d339c
This commit is contained in:
parent
774dc3cd51
commit
fa21cafc1c
1 changed files with 760 additions and 44 deletions
|
|
@ -161,6 +161,7 @@ import android.net.InetAddresses;
|
|||
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;
|
||||
|
|
@ -1775,7 +1776,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
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);
|
||||
|
|
@ -4123,6 +4124,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
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;
|
||||
|
|
@ -8083,13 +8089,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
* @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");
|
||||
|
|
@ -8107,12 +8118,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
// 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);
|
||||
}
|
||||
|
|
@ -8120,7 +8139,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
|
||||
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
|
||||
|
|
@ -8128,6 +8148,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
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
|
||||
|
|
@ -8135,9 +8156,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
// 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)
|
||||
|
|
@ -8872,6 +8893,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
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).
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue