Merge "Support checking kernel bitness via JNI" into main

This commit is contained in:
Yan Yan 2024-01-18 18:13:38 +00:00 • committed by Gerrit Code Review
commit 77ee99872d
3 changed files with 20 additions and 1 deletions

View file

@ -24,6 +24,7 @@
#include <string.h>
#include <bpf/BpfClassic.h>
#include <bpf/KernelUtils.h>
#include <DnsProxydProtocol.h> // NETID_USE_LOCAL_NAMESERVERS
#include <nativehelper/JNIPlatformHelp.h>
#include <nativehelper/ScopedPrimitiveArray.h>
@ -250,6 +251,10 @@ static void android_net_utils_setsockoptBytes(JNIEnv *env, jclass clazz, jobject
}
}
static jboolean android_net_utils_isKernel64Bit(JNIEnv *env, jclass clazz) {
return bpf::isKernel64Bit();
}
// ----------------------------------------------------------------------------
/*
@ -272,6 +277,7 @@ static const JNINativeMethod gNetworkUtilMethods[] = {
{ "getDnsNetwork", "()Landroid/net/Network;", (void*) android_net_utils_getDnsNetwork },
{ "setsockoptBytes", "(Ljava/io/FileDescriptor;II[B)V",
(void*) android_net_utils_setsockoptBytes},
{ "isKernel64Bit", "()Z", (void*) android_net_utils_isKernel64Bit },
};
// clang-format on

View file

@ -438,4 +438,6 @@ public class NetworkUtils {
public static native void setsockoptBytes(FileDescriptor fd, int level, int option,
byte[] value) throws ErrnoException;
/** Returns whether the Linux Kernel is 64 bit */
public static native boolean isKernel64Bit();
}

View file

@ -21,8 +21,14 @@ import static android.system.OsConstants.IPPROTO_ICMPV6;
import static android.system.OsConstants.SOCK_DGRAM;
import static android.system.OsConstants.SOL_SOCKET;
import static android.system.OsConstants.SO_RCVTIMEO;
import static com.android.compatibility.common.util.PropertyUtil.getVsrApiLevel;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import android.os.Build;
import android.system.ErrnoException;
import android.system.Os;
@ -38,7 +44,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.FileDescriptor;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -167,4 +172,10 @@ public class NetworkUtilsTest {
assertEquals(writeTimeval, readTimeval);
SocketUtils.closeSocketQuietly(sock);
}
@Test
public void testIsKernel64Bit() {
assumeTrue(getVsrApiLevel() > Build.VERSION_CODES.TIRAMISU);
assertTrue(NetworkUtils.isKernel64Bit());
}
}