Add @RequiresApi(TIRAMISU) to BpfNetMapsUtils

With this annotation, errorprone build will fail if callers don't check
sdk version before calling any methods in BpfNetMapsUtils.

Bug: 328732146
Test: TH
Change-Id: Ifa52dc1d2766f8d46dfdc4f6ca9dbb963406c084
This commit is contained in:
Motomu Utsumi 2024-03-26 18:25:39 +09:00
parent c04493234e
commit 2c248d2108
3 changed files with 10 additions and 0 deletions

View file

@ -53,12 +53,15 @@ import static android.net.ConnectivityManager.FIREWALL_RULE_ALLOW;
import static android.net.ConnectivityManager.FIREWALL_RULE_DENY;
import static android.system.OsConstants.EINVAL;
import android.os.Build;
import android.os.Process;
import android.os.ServiceSpecificException;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Pair;
import androidx.annotation.RequiresApi;
import com.android.modules.utils.build.SdkLevel;
import com.android.net.module.util.IBpfMap;
import com.android.net.module.util.Struct;
@ -76,6 +79,8 @@ import java.util.StringJoiner;
// Note that this class should be put into bootclasspath instead of static libraries.
// Because modules could have different copies of this class if this is statically linked,
// which would be problematic if the definitions in these modules are not synchronized.
// Note that NetworkStack can not use this before U due to b/326143935
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
public class BpfNetMapsUtils {
// Bitmaps for calculating whether a given uid is blocked by firewall chains.
private static final long sMaskDropIfSet;

View file

@ -579,6 +579,7 @@ public class BpfNetMaps {
return BpfNetMapsUtils.getUidRule(sUidOwnerMap, childChain, uid);
}
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private Set<Integer> getUidsMatchEnabled(final int childChain) throws ErrnoException {
final long match = getMatchByFirewallChain(childChain);
Set<Integer> uids = new ArraySet<>();
@ -607,6 +608,7 @@ public class BpfNetMaps {
* @param childChain target chain
* @return Set of uids
*/
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
public Set<Integer> getUidsWithAllowRuleOnAllowListChain(final int childChain)
throws ErrnoException {
if (!isFirewallAllowList(childChain)) {
@ -628,6 +630,7 @@ public class BpfNetMaps {
* @param childChain target chain
* @return Set of uids
*/
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
public Set<Integer> getUidsWithDenyRuleOnDenyListChain(final int childChain)
throws ErrnoException {
if (isFirewallAllowList(childChain)) {
@ -922,6 +925,7 @@ public class BpfNetMaps {
return sj.toString();
}
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private void dumpOwnerMatchConfig(final IndentingPrintWriter pw) {
try {
final long match = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY).val;

View file

@ -13555,6 +13555,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
return rule;
}
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private void closeSocketsForFirewallChainLocked(final int chain)
throws ErrnoException, SocketException, InterruptedIOException {
if (BpfNetMapsUtils.isFirewallAllowList(chain)) {