Merge "Replace NetworkPolicyManagerInternal#isUidNetworkingBlocked()" am: 016c1500f4 am: 1340c9e3d2

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1535722

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I623a01c29978908b213e888ffebc06f38d5ee085
This commit is contained in:
Paul Hu
2021-01-12 11:11:08 +00:00
committed by Automerger Merge Worker

View File

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