rebootescrow: use property to find device

To allow vendors to have different names for their devices, read the
device name from a system property.

Test: atest VtsHalRebootEscrowTargetTest
Bug: 146400078
Change-Id: I93f37e14139532ab192795dcad27c586545a1bc4
This commit is contained in:
Kenny Root
2020-01-24 17:36:47 -08:00
parent d8f473f231
commit 7e6f5f97c2
3 changed files with 14 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ namespace rebootescrow {
using ::android::base::unique_fd;
ndk::ScopedAStatus RebootEscrow::storeKey(const std::vector<int8_t>& kek) {
int rawFd = TEMP_FAILURE_RETRY(::open(REBOOT_ESCROW_DEVICE, O_WRONLY | O_NOFOLLOW | O_CLOEXEC));
int rawFd = TEMP_FAILURE_RETRY(::open(devicePath_.c_str(), O_WRONLY | O_NOFOLLOW | O_CLOEXEC));
unique_fd fd(rawFd);
if (fd.get() < 0) {
LOG(WARNING) << "Could not open reboot escrow device";
@@ -48,7 +48,7 @@ ndk::ScopedAStatus RebootEscrow::storeKey(const std::vector<int8_t>& kek) {
}
ndk::ScopedAStatus RebootEscrow::retrieveKey(std::vector<int8_t>* _aidl_return) {
int rawFd = TEMP_FAILURE_RETRY(::open(REBOOT_ESCROW_DEVICE, O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
int rawFd = TEMP_FAILURE_RETRY(::open(devicePath_.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
unique_fd fd(rawFd);
if (fd.get() < 0) {
LOG(WARNING) << "Could not open reboot escrow device";

View File

@@ -23,11 +23,14 @@ namespace android {
namespace hardware {
namespace rebootescrow {
static const char* REBOOT_ESCROW_DEVICE = "/dev/access-kregistry";
class RebootEscrow : public BnRebootEscrow {
public:
explicit RebootEscrow(const std::string& devicePath) : devicePath_(devicePath) {}
ndk::ScopedAStatus storeKey(const std::vector<int8_t>& kek) override;
ndk::ScopedAStatus retrieveKey(std::vector<int8_t>* _aidl_return) override;
private:
const std::string devicePath_;
};
} // namespace rebootescrow

View File

@@ -17,15 +17,21 @@
#include "rebootescrow-impl/RebootEscrow.h"
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
using aidl::android::hardware::rebootescrow::RebootEscrow;
constexpr auto kRebootEscrowDeviceProperty = "ro.rebootescrow.device";
constexpr auto kRebootEscrowDeviceDefault = "/dev/access-kregistry";
int main() {
ABinderProcess_setThreadPoolMaxThreadCount(0);
auto re = ndk::SharedRefBase::make<RebootEscrow>();
auto rebootEscrowDevicePath =
android::base::GetProperty(kRebootEscrowDeviceProperty, kRebootEscrowDeviceDefault);
auto re = ndk::SharedRefBase::make<RebootEscrow>(rebootEscrowDevicePath);
const std::string instance = std::string() + RebootEscrow::descriptor + "/default";
binder_status_t status = AServiceManager_addService(re->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK);