NetBpfLoad: Update build constraints & comments.

Corrected the comment in Android.bp regarding the target SDK version. In NetBpfLoad.cpp, added specific handling for RiscV builds to account for its undefined minimum API level. Added an error to ensure NetBpfLoad is always compiled within an APEX. Clarified that `minSupportedKernelVer` must be 0 for APEX builds to enable runtime kernel version enforcement.

Bug: 438908493
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie3affbfd702ff1f6d5f2887b6f56ade0ed7fb5dd
This commit is contained in:
Maciej Żenczykowski 2025-08-15 11:32:26 -07:00
commit 95e4958769
2 changed files with 23 additions and 3 deletions

View file

@ -52,7 +52,7 @@ cc_binary {
"com.android.tethering",
"//apex_available:platform",
],
// really should be Android 13/T (33), but we cannot include binaries built
// really should be Android 12/S (31), but we cannot include binaries built
// against newer sdk in the apex, which still targets 30(R):
// module "netbpfload" variant "android_x86_apex30": should support
// min_sdk_version(30) for "com.android.tethering": newer SDK(34).

View file

@ -88,11 +88,31 @@ using std::vector;
namespace android {
namespace bpf {
#if !defined(__riscv)
// Due to support for RiscV not yet having been released,
// there is no minimum supported api level for it.
//
// Thus in //build/soong/cc/api_level.go
// MinApiForArch(riscv64)
// will return FutureApiLevel which results in
// __ANDROID_API__ == __ANDROID_MIN_SDK_VERSION__ == 10000
//
// Normally __ANDROID_API__ is 'min_sdk_version = 30' from Android.bp
#if defined(__riscv)
static_assert(__ANDROID_API__ == 10000, "TODO: add proper mainline riscv support");
#else
static_assert(__ANDROID_API__ == 30, "NetBpfLoad must be compiled for 30/R");
static_assert(!minSupportedKernelVer, "NetBpfLoad must not assume min kver");
#endif
#ifndef __ANDROID_APEX__
#error "NetBpfLoad must be compiled into the Tethering Mainline Module APEX"
#endif
// We want to be able to run time enforce minimum kernel versions,
// which means we can't just assume the minimum applies,
// for this reason the value of 'minSupportedKernelVer'
// should be 0 for APEX/mainline builds.
static_assert(!minSupportedKernelVer, "NetBpfLoad must not assume min kver");
// Returns the build type string (from ro.build.type).
const std::string& getBuildType() {
static std::string t = GetProperty("ro.build.type", "unknown");