Bpf: open code PRE_T - too complex for errorprone linter
Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I1ad2d0dd288882e84925f0b59961dcd33612f3f7
This commit is contained in:
parent
1870f94a9e
commit
0d450d3e4d
2 changed files with 10 additions and 12 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
|
|
|
|||
Loading…
Reference in a new issue