diff --git a/framework/src/android/net/BpfNetMapsUtils.java b/framework/src/android/net/BpfNetMapsUtils.java index 11d610cbfe..0be30bb281 100644 --- a/framework/src/android/net/BpfNetMapsUtils.java +++ b/framework/src/android/net/BpfNetMapsUtils.java @@ -125,13 +125,11 @@ public class BpfNetMapsUtils { return sj.toString(); } - public static final boolean PRE_T = !SdkLevel.isAtLeastT(); - /** * Throw UnsupportedOperationException if SdkLevel is before T. */ public static void throwIfPreT(final String msg) { - if (PRE_T) { + if (!SdkLevel.isAtLeastT()) { throw new UnsupportedOperationException(msg); } } diff --git a/service/src/com/android/server/BpfNetMaps.java b/service/src/com/android/server/BpfNetMaps.java index a76d594a9f..a7fddd08f0 100644 --- a/service/src/com/android/server/BpfNetMaps.java +++ b/service/src/com/android/server/BpfNetMaps.java @@ -31,7 +31,6 @@ import static android.net.BpfNetMapsConstants.PENALTY_BOX_MATCH; import static android.net.BpfNetMapsConstants.UID_OWNER_MAP_PATH; import static android.net.BpfNetMapsConstants.UID_PERMISSION_MAP_PATH; import static android.net.BpfNetMapsConstants.UID_RULES_CONFIGURATION_KEY; -import static android.net.BpfNetMapsUtils.PRE_T; import static android.net.BpfNetMapsUtils.getMatchByFirewallChain; import static android.net.BpfNetMapsUtils.isFirewallAllowList; import static android.net.BpfNetMapsUtils.matchToString; @@ -68,6 +67,7 @@ import androidx.annotation.RequiresApi; import com.android.internal.annotations.VisibleForTesting; import com.android.modules.utils.BackgroundThread; +import com.android.modules.utils.build.SdkLevel; import com.android.net.module.util.BpfDump; import com.android.net.module.util.BpfMap; import com.android.net.module.util.IBpfMap; @@ -95,7 +95,7 @@ import java.util.StringJoiner; */ public class BpfNetMaps { static { - if (!PRE_T) { + if (SdkLevel.isAtLeastT()) { System.loadLibrary("service-connectivity"); } } @@ -356,7 +356,7 @@ public class BpfNetMaps { public BpfNetMaps(final Context context) { this(context, null); - if (PRE_T) throw new IllegalArgumentException("BpfNetMaps need to use netd before T"); + if (!SdkLevel.isAtLeastT()) throw new IllegalArgumentException("BpfNetMaps need to use netd before T"); } public BpfNetMaps(final Context context, final INetd netd) { @@ -365,7 +365,7 @@ public class BpfNetMaps { @VisibleForTesting public BpfNetMaps(final Context context, final INetd netd, final Dependencies deps) { - if (!PRE_T) { + if (SdkLevel.isAtLeastT()) { ensureInitialized(context); } mNetd = netd; @@ -379,7 +379,7 @@ public class BpfNetMaps { } private void throwIfPreT(final String msg) { - if (PRE_T) { + if (!SdkLevel.isAtLeastT()) { throw new UnsupportedOperationException(msg); } } @@ -720,7 +720,7 @@ public class BpfNetMaps { * cause of the failure. */ public void addUidInterfaceRules(final String ifName, final int[] uids) throws RemoteException { - if (PRE_T) { + if (!SdkLevel.isAtLeastT()) { mNetd.firewallAddUidInterfaceRules(ifName, uids); return; } @@ -758,7 +758,7 @@ public class BpfNetMaps { * cause of the failure. */ public void removeUidInterfaceRules(final int[] uids) throws RemoteException { - if (PRE_T) { + if (!SdkLevel.isAtLeastT()) { mNetd.firewallRemoveUidInterfaceRules(uids); return; } @@ -837,7 +837,7 @@ public class BpfNetMaps { * @throws RemoteException when netd has crashed. */ public void setNetPermForUids(final int permissions, final int[] uids) throws RemoteException { - if (PRE_T) { + if (!SdkLevel.isAtLeastT()) { mNetd.trafficSetNetPermForUids(permissions, uids); return; } @@ -1027,7 +1027,7 @@ public class BpfNetMaps { @RequiresApi(Build.VERSION_CODES.TIRAMISU) public void dump(final IndentingPrintWriter pw, final FileDescriptor fd, boolean verbose) throws IOException, ServiceSpecificException { - if (PRE_T) { + if (!SdkLevel.isAtLeastT()) { throw new ServiceSpecificException( EOPNOTSUPP, "dumpsys connectivity trafficcontroller dump not available on pre-T" + " devices, use dumpsys netd trafficcontroller instead.");