TestBpfMap implements IBpfMap instead of extends BpfMap

Bug: 217624062
Test: m, atest BpfCoordinatorTest BpfNetMapsTest
Change-Id: I41153a569d79031f0841432c6e83bef2170a33e4
diff --git a/staticlibs/device/com/android/net/module/util/BpfMap.java b/staticlibs/device/com/android/net/module/util/BpfMap.java
index f7019a5..2267f31 100644
--- a/staticlibs/device/com/android/net/module/util/BpfMap.java
+++ b/staticlibs/device/com/android/net/module/util/BpfMap.java
@@ -24,9 +24,6 @@
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-
-import com.android.net.module.util.Struct;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -104,22 +101,6 @@
         mValueSize = Struct.getSize(value);
     }
 
-     /**
-     * Constructor for testing only.
-     * The derived class implements an internal mocked map. It need to implement all functions
-     * which are related with the native BPF map because the BPF map handler is not initialized.
-     * See BpfCoordinatorTest#TestBpfMap.
-     * TODO: remove once TestBpfMap derive from IBpfMap.
-     */
-    @VisibleForTesting
-    protected BpfMap(final Class<K> key, final Class<V> value) {
-        mMapFd = null;  // unused
-        mKeyClass = key;
-        mValueClass = value;
-        mKeySize = Struct.getSize(key);
-        mValueSize = Struct.getSize(value);
-    }
-
     /**
      * Update an existing or create a new key -> value entry in an eBbpf map.
      * (use insertOrReplaceEntry() if you need to know whether insert or replace happened)
diff --git a/staticlibs/device/com/android/net/module/util/IBpfMap.java b/staticlibs/device/com/android/net/module/util/IBpfMap.java
index dce369a..83ff875 100644
--- a/staticlibs/device/com/android/net/module/util/IBpfMap.java
+++ b/staticlibs/device/com/android/net/module/util/IBpfMap.java
@@ -19,6 +19,7 @@
 
 import androidx.annotation.NonNull;
 
+import java.io.IOException;
 import java.util.NoSuchElementException;
 
 /**
@@ -74,4 +75,8 @@
 
     /** Clears the map. */
     void clear() throws ErrnoException;
+
+    /** Close for AutoCloseable. */
+    @Override
+    void close() throws IOException;
 }
diff --git a/staticlibs/testutils/devicetests/com/android/testutils/TestBpfMap.java b/staticlibs/testutils/devicetests/com/android/testutils/TestBpfMap.java
index 3883511..733bd98 100644
--- a/staticlibs/testutils/devicetests/com/android/testutils/TestBpfMap.java
+++ b/staticlibs/testutils/devicetests/com/android/testutils/TestBpfMap.java
@@ -20,10 +20,10 @@
 
 import androidx.annotation.NonNull;
 
-import com.android.net.module.util.BpfMap;
-import com.android.net.module.util.IBpfMap.ThrowingBiConsumer;
+import com.android.net.module.util.IBpfMap;
 import com.android.net.module.util.Struct;
 
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.NoSuchElementException;
@@ -32,20 +32,19 @@
 
 /**
  *
- * Fake BPF map class for tests that have no no privilege to access real BPF maps. All member
- * functions which eventually call JNI to access the real native BPF map are overridden.
+ * Fake BPF map class for tests that have no privilege to access real BPF maps. TestBpfMap does not
+ * load JNI and all member functions do not access real BPF maps.
  *
- * Inherits from BpfMap instead of implementing IBpfMap so that any class using a BpfMap can use
- * this class in its tests.
+ * Implements IBpfMap so that any class using IBpfMap can use this class in its tests.
  *
  * @param <K> the key type
  * @param <V> the value type
  */
-public class TestBpfMap<K extends Struct, V extends Struct> extends BpfMap<K, V> {
+public class TestBpfMap<K extends Struct, V extends Struct> implements IBpfMap<K, V> {
     private final ConcurrentHashMap<K, V> mMap = new ConcurrentHashMap<>();
 
+    // TODO: Remove this constructor
     public TestBpfMap(final Class<K> key, final Class<V> value) {
-        super(key, value);
     }
 
     @Override
@@ -133,4 +132,8 @@
         // TODO: consider using mocked #getFirstKey and #deleteEntry to implement.
         mMap.clear();
     }
+
+    @Override
+    public void close() throws IOException {
+    }
 }