Remove unnecessary null check
Address review comments from aosp/2131752 and aosp/2117045
sConfigurationMap must have a entry for UID_RULES_CONFIGURATION_KEY
because this bpf map is an array
Bug: 217624062
Test: atest BpfNetMapsTest
Change-Id: Ic52623e11c1f53e363416d57c0d8705d5510ef04
diff --git a/service/src/com/android/server/BpfNetMaps.java b/service/src/com/android/server/BpfNetMaps.java
index 81e9e3a..6e107c2 100644
--- a/service/src/com/android/server/BpfNetMaps.java
+++ b/service/src/com/android/server/BpfNetMaps.java
@@ -25,7 +25,6 @@
import static android.net.ConnectivityManager.FIREWALL_CHAIN_RESTRICTED;
import static android.net.ConnectivityManager.FIREWALL_CHAIN_STANDBY;
import static android.system.OsConstants.EINVAL;
-import static android.system.OsConstants.ENOENT;
import static android.system.OsConstants.EOPNOTSUPP;
import android.net.INetd;
@@ -239,11 +238,6 @@
try {
synchronized (sUidRulesConfigBpfMapLock) {
final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
- if (config == null) {
- throw new ServiceSpecificException(ENOENT,
- "Unable to get firewall chain status: sConfigurationMap does not have"
- + " entry for UID_RULES_CONFIGURATION_KEY");
- }
final long newConfig = enable ? (config.val | match) : (config.val & ~match);
sConfigurationMap.updateEntry(UID_RULES_CONFIGURATION_KEY, new U32(newConfig));
}
@@ -268,11 +262,6 @@
final long match = getMatchByFirewallChain(childChain);
try {
final U32 config = sConfigurationMap.getValue(UID_RULES_CONFIGURATION_KEY);
- if (config == null) {
- throw new ServiceSpecificException(ENOENT,
- "Unable to get firewall chain status: sConfigurationMap does not have"
- + " entry for UID_RULES_CONFIGURATION_KEY");
- }
return (config.val & match) != 0;
} catch (ErrnoException e) {
throw new ServiceSpecificException(e.errno,
diff --git a/tests/unit/java/com/android/server/BpfNetMapsTest.java b/tests/unit/java/com/android/server/BpfNetMapsTest.java
index 634ec9c..e9fad9b 100644
--- a/tests/unit/java/com/android/server/BpfNetMapsTest.java
+++ b/tests/unit/java/com/android/server/BpfNetMapsTest.java
@@ -175,14 +175,6 @@
}
@Test
- @IgnoreUpTo(Build.VERSION_CODES.S_V2)
- public void testIsChainEnabledMissingConfiguration() {
- // sConfigurationMap does not have entry for UID_RULES_CONFIGURATION_KEY
- assertThrows(ServiceSpecificException.class,
- () -> mBpfNetMaps.isChainEnabled(FIREWALL_CHAIN_DOZABLE));
- }
-
- @Test
@IgnoreAfter(Build.VERSION_CODES.S_V2)
public void testIsChainEnabledBeforeT() {
assertThrows(UnsupportedOperationException.class,
@@ -252,14 +244,6 @@
}
@Test
- @IgnoreUpTo(Build.VERSION_CODES.S_V2)
- public void testSetChildChainMissingConfiguration() {
- // sConfigurationMap does not have entry for UID_RULES_CONFIGURATION_KEY
- assertThrows(ServiceSpecificException.class,
- () -> mBpfNetMaps.setChildChain(FIREWALL_CHAIN_DOZABLE, true /* enable */));
- }
-
- @Test
@IgnoreAfter(Build.VERSION_CODES.S_V2)
public void testSetChildChainBeforeT() {
assertThrows(UnsupportedOperationException.class,