Reapply "Use bpf map based isUidNetworkingBlocked on V+"
This reverts commit a658220234.
Change-Id: I53acd7ff4821a65583b2ad936e22efaa21965a14
This commit is contained in:
parent
d6ae2944dd
commit
a08692f7c7
3 changed files with 26 additions and 1 deletions
|
|
@ -889,6 +889,25 @@ public class BpfNetMaps {
|
|||
return (blockedReasons & BLOCKED_METERED_REASON_MASK) != BLOCKED_REASON_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return whether the network is blocked by firewall chains for the given uid.
|
||||
*
|
||||
* Note that {@link #getDataSaverEnabled()} has a latency before V.
|
||||
*
|
||||
* @param uid The target uid.
|
||||
* @param isNetworkMetered Whether the target network is metered.
|
||||
*
|
||||
* @return True if the network is blocked. Otherwise, false.
|
||||
* @throws ServiceSpecificException if the read fails.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||
public boolean isUidNetworkingBlocked(final int uid, boolean isNetworkMetered) {
|
||||
return BpfNetMapsUtils.isUidNetworkingBlocked(uid, isNetworkMetered,
|
||||
sConfigurationMap, sUidOwnerMap, sDataSaverEnabledMap);
|
||||
}
|
||||
|
||||
/** Register callback for statsd to pull atom. */
|
||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||
public void setPullAtomCallback(final Context context) {
|
||||
|
|
|
|||
|
|
@ -2240,7 +2240,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
final boolean metered = nc == null ? true : nc.isMetered();
|
||||
return mPolicyManager.isUidNetworkingBlocked(uid, metered);
|
||||
if (mDeps.isAtLeastV()) {
|
||||
return mBpfNetMaps.isUidNetworkingBlocked(uid, metered);
|
||||
} else {
|
||||
return mPolicyManager.isUidNetworkingBlocked(uid, metered);
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1727,6 +1727,8 @@ public class ConnectivityServiceTest {
|
|||
private void mockUidNetworkingBlocked() {
|
||||
doAnswer(i -> isUidBlocked(mBlockedReasons, i.getArgument(1))
|
||||
).when(mNetworkPolicyManager).isUidNetworkingBlocked(anyInt(), anyBoolean());
|
||||
doAnswer(i -> isUidBlocked(mBlockedReasons, i.getArgument(1))
|
||||
).when(mBpfNetMaps).isUidNetworkingBlocked(anyInt(), anyBoolean());
|
||||
}
|
||||
|
||||
private boolean isUidBlocked(int blockedReasons, boolean meteredNetwork) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue