Set min_sdk_version for the test payload
We now have GTS tests that run on previous Android releases. Because we
didn't set the min_sdk_version of the native library, loading the
library in Microdroid failed with:
'cannot locate symbol "AVmPayload_readRollbackProtectedSecret"'.
Setting min_sdk_version makes APIs that were added after the
min_sdk_version use weak linking, so loading the library will succeed.
This patch alone is not enough to fix the GTS test failures, since
loading still fails with a different error which I'm still looking into:
'dlopen failed: cannot locate symbol "AIBinder_Class_setTransactionCodeToFunctionNameMap'
Bug: 389781453
Bug: 388702766
Test: atest MicrodroidTestApp.GTS
Change-Id: If14d82b92484bfe9d206b8d86d5ea07fad9ecfe6
diff --git a/tests/testapk/Android.bp b/tests/testapk/Android.bp
index d0e045b..99300e2 100644
--- a/tests/testapk/Android.bp
+++ b/tests/testapk/Android.bp
@@ -173,6 +173,8 @@
"liblog",
"libprotobuf-cpp-lite-ndk",
],
+ // We've added support for updatable payloads in Android U.
+ min_sdk_version: "UpsideDownCake",
}
cc_library_shared {
diff --git a/tests/testapk/src/native/testbinary.cpp b/tests/testapk/src/native/testbinary.cpp
index 06c7e9d..2ab73a4 100644
--- a/tests/testapk/src/native/testbinary.cpp
+++ b/tests/testapk/src/native/testbinary.cpp
@@ -348,25 +348,40 @@
}
ScopedAStatus insecurelyReadPayloadRpData(std::array<uint8_t, 32>* out) override {
- int32_t ret = AVmPayload_readRollbackProtectedSecret(out->data(), 32);
- if (ret != 32) {
- return ScopedAStatus::fromServiceSpecificError(ret);
+ if (__builtin_available(android 36, *)) {
+ int32_t ret = AVmPayload_readRollbackProtectedSecret(out->data(), 32);
+ if (ret != 32) {
+ return ScopedAStatus::fromServiceSpecificError(ret);
+ }
+ return ScopedAStatus::ok();
+ } else {
+ return ScopedAStatus::fromExceptionCodeWithMessage(EX_SERVICE_SPECIFIC,
+ "not available before SDK 36");
}
- return ScopedAStatus::ok();
}
ScopedAStatus insecurelyWritePayloadRpData(
const std::array<uint8_t, 32>& inputData) override {
- int32_t ret = AVmPayload_writeRollbackProtectedSecret(inputData.data(), 32);
- if (ret != 32) {
- return ScopedAStatus::fromServiceSpecificError(ret);
+ if (__builtin_available(android 36, *)) {
+ int32_t ret = AVmPayload_writeRollbackProtectedSecret(inputData.data(), 32);
+ if (ret != 32) {
+ return ScopedAStatus::fromServiceSpecificError(ret);
+ }
+ return ScopedAStatus::ok();
+ } else {
+ return ScopedAStatus::fromExceptionCodeWithMessage(EX_SERVICE_SPECIFIC,
+ "not available before SDK 36");
}
- return ScopedAStatus::ok();
}
ScopedAStatus isNewInstance(bool* is_new_instance_out) override {
- *is_new_instance_out = AVmPayload_isNewInstance();
- return ScopedAStatus::ok();
+ if (__builtin_available(android 36, *)) {
+ *is_new_instance_out = AVmPayload_isNewInstance();
+ return ScopedAStatus::ok();
+ } else {
+ return ScopedAStatus::fromExceptionCodeWithMessage(EX_SERVICE_SPECIFIC,
+ "not available before SDK 36");
+ }
}
ScopedAStatus quit() override { exit(0); }