Merge "Replace NetworkPolicyManagerInternal#isUidNetworkingBlocked()"

This commit is contained in:
Paul Hu
2021-01-12 09:53:05 +00:00
committed by Gerrit Code Review

View File

@@ -1331,15 +1331,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
/**
* Check if UID should be blocked from using the specified network.
*/
private boolean isNetworkWithLinkPropertiesBlocked(LinkProperties lp, int uid,
boolean ignoreBlocked) {
private boolean isNetworkWithCapabilitiesBlocked(@Nullable final NetworkCapabilities nc,
final int uid, final boolean ignoreBlocked) {
// Networks aren't blocked when ignoring blocked status
if (ignoreBlocked) {
return false;
}
if (isUidBlockedByVpn(uid, mVpnBlockedUidRanges)) return true;
final String iface = (lp == null ? "" : lp.getInterfaceName());
return mPolicyManagerInternal.isUidNetworkingBlocked(uid, iface);
final long ident = Binder.clearCallingIdentity();
try {
final boolean metered = nc == null ? true : nc.isMetered();
return mPolicyManager.isUidNetworkingBlocked(uid, metered);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
private void maybeLogBlockedNetworkInfo(NetworkInfo ni, int uid) {
@@ -1377,12 +1382,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
/**
* Apply any relevant filters to {@link NetworkState} for the given UID. For
* example, this may mark the network as {@link DetailedState#BLOCKED} based
* on {@link #isNetworkWithLinkPropertiesBlocked}.
* on {@link #isNetworkWithCapabilitiesBlocked}.
*/
private void filterNetworkStateForUid(NetworkState state, int uid, boolean ignoreBlocked) {
if (state == null || state.networkInfo == null || state.linkProperties == null) return;
if (isNetworkWithLinkPropertiesBlocked(state.linkProperties, uid, ignoreBlocked)) {
if (isNetworkWithCapabilitiesBlocked(state.networkCapabilities, uid,
ignoreBlocked)) {
state.networkInfo.setDetailedState(DetailedState.BLOCKED, null, null);
}
synchronized (mVpns) {
@@ -1442,8 +1448,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
nai = getDefaultNetwork();
if (nai != null
&& isNetworkWithLinkPropertiesBlocked(nai.linkProperties, uid, ignoreBlocked)) {
if (nai != null && isNetworkWithCapabilitiesBlocked(
nai.networkCapabilities, uid, ignoreBlocked)) {
nai = null;
}
return nai != null ? nai.network : null;
@@ -1515,7 +1521,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
enforceAccessPermission();
final int uid = mDeps.getCallingUid();
NetworkState state = getFilteredNetworkState(networkType, uid);
if (!isNetworkWithLinkPropertiesBlocked(state.linkProperties, uid, false)) {
if (!isNetworkWithCapabilitiesBlocked(state.networkCapabilities, uid, false)) {
return state.network;
}
return null;
@@ -4473,7 +4479,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (!nai.everConnected) {
return;
}
if (isNetworkWithLinkPropertiesBlocked(nai.linkProperties, uid, false)) {
final NetworkCapabilities nc = getNetworkCapabilitiesInternal(nai);
if (isNetworkWithCapabilitiesBlocked(nc, uid, false)) {
return;
}
nai.networkMonitor().forceReevaluation(uid);