Load JNI in all classes that have native methods.

The tethering module uses JNI in various classes, but only calls
System.loadLibrary in TetheringService#makeTethering. This means
that:

1. Any test that uses a class that uses JNI must load the
   library itself.
2. Any code that runs before TetheringService#makeTethering could
   potentially crash if it uses JNI. We may never have such code
   though.

Instead, make every class that has a native method load the JNI
library itself at static initialization time. This guarantees
that the class will have the JNI code available in any context
(production, test, etc.)

System.loadLibrary is documented not to do anything if called
more than once with the same library name:
https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#loadLibrary(java.lang.String)

and the implementation has a lock so it is safe to call from
multiple threads concurrently.

Test: builds, boots, tethering starts
Test: atest TetheringCoverageTests
Change-Id: I9c0147ae9a28877f416aaff387b426d304ae552d
diff --git a/Tethering/src/android/net/util/TetheringUtils.java b/Tethering/src/android/net/util/TetheringUtils.java
index 706d78c..9e7cc2f 100644
--- a/Tethering/src/android/net/util/TetheringUtils.java
+++ b/Tethering/src/android/net/util/TetheringUtils.java
@@ -36,6 +36,10 @@
  * {@hide}
  */
 public class TetheringUtils {
+    static {
+        System.loadLibrary("tetherutilsjni");
+    }
+
     public static final byte[] ALL_NODES = new byte[] {
         (byte) 0xff, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
     };
diff --git a/Tethering/src/com/android/networkstack/tethering/BpfMap.java b/Tethering/src/com/android/networkstack/tethering/BpfMap.java
index bc01dbd..9a9376f 100644
--- a/Tethering/src/com/android/networkstack/tethering/BpfMap.java
+++ b/Tethering/src/com/android/networkstack/tethering/BpfMap.java
@@ -41,6 +41,10 @@
  * @param <V> the value of the map.
  */
 public class BpfMap<K extends Struct, V extends Struct> implements AutoCloseable {
+    static {
+        System.loadLibrary("tetherutilsjni");
+    }
+
     // Following definitions from kernel include/uapi/linux/bpf.h
     public static final int BPF_F_RDWR = 0;
     public static final int BPF_F_RDONLY = 1 << 3;
diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringService.java b/Tethering/src/com/android/networkstack/tethering/TetheringService.java
index 613328d..c69dc49 100644
--- a/Tethering/src/com/android/networkstack/tethering/TetheringService.java
+++ b/Tethering/src/com/android/networkstack/tethering/TetheringService.java
@@ -82,7 +82,6 @@
      */
     @VisibleForTesting
     public Tethering makeTethering(TetheringDependencies deps) {
-        System.loadLibrary("tetherutilsjni");
         return new Tethering(deps);
     }