Add readProperty to the test service
This method will return a system property of guest.
Bug: 203483081
Test: atest MicrodroidHostTestCases
Change-Id: Iba4c6420ea414dd59c2dc80b1fdef9ef38b7b1b3
diff --git a/tests/aidl/com/android/microdroid/testservice/ITestService.aidl b/tests/aidl/com/android/microdroid/testservice/ITestService.aidl
index cdcb2bd..208d61f 100644
--- a/tests/aidl/com/android/microdroid/testservice/ITestService.aidl
+++ b/tests/aidl/com/android/microdroid/testservice/ITestService.aidl
@@ -21,4 +21,7 @@
/* add two integers. */
int addInteger(int a, int b);
+
+ /* read a system property. */
+ String readProperty(String prop);
}
diff --git a/tests/testapk/src/native/testbinary.cpp b/tests/testapk/src/native/testbinary.cpp
index f56b261..5435547 100644
--- a/tests/testapk/src/native/testbinary.cpp
+++ b/tests/testapk/src/native/testbinary.cpp
@@ -16,6 +16,7 @@
#include <aidl/android/system/keystore2/IKeystoreService.h>
#include <aidl/android/system/virtualmachineservice/IVirtualMachineService.h>
#include <aidl/com/android/microdroid/testservice/BnTestService.h>
+#include <android-base/properties.h>
#include <android-base/result.h>
#include <android-base/unique_fd.h>
#include <android/binder_auto_utils.h>
@@ -29,6 +30,7 @@
#include <unistd.h>
#include <binder_rpc_unstable.hpp>
+#include <string>
using aidl::android::hardware::security::keymint::Algorithm;
using aidl::android::hardware::security::keymint::Digest;
@@ -204,6 +206,17 @@
*out = a + b;
return ndk::ScopedAStatus::ok();
}
+
+ ndk::ScopedAStatus readProperty(const std::string& prop, std::string* out) override {
+ *out = android::base::GetProperty(prop, "");
+ if (out->empty()) {
+ std::string msg = "cannot find property " + prop;
+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_SERVICE_SPECIFIC,
+ msg.c_str());
+ }
+
+ return ndk::ScopedAStatus::ok();
+ }
};
auto testService = ndk::SharedRefBase::make<TestService>();