From af611582861f916be1d3ca9c612ea777518434c0 Mon Sep 17 00:00:00 2001 From: ChengYou Ho Date: Tue, 7 Dec 2021 14:42:37 +0800 Subject: [PATCH] Weaver: modify default HAL for passing VTS Bug: 178339800 Test: VtsHalWeaverTargetTest Change-Id: I5b6991874422448b45a30d221ae4922ae7e2b0eb --- weaver/aidl/default/Weaver.cpp | 36 +++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/weaver/aidl/default/Weaver.cpp b/weaver/aidl/default/Weaver.cpp index 56d9c4da8b..6b77924be7 100644 --- a/weaver/aidl/default/Weaver.cpp +++ b/weaver/aidl/default/Weaver.cpp @@ -15,30 +15,52 @@ */ #include "Weaver.h" +#include namespace aidl { namespace android { namespace hardware { namespace weaver { +struct Slotinfo { + int slot_id; + std::vector key; + std::vector value; +}; + +std::array slot_array; // Methods from ::android::hardware::weaver::IWeaver follow. ::ndk::ScopedAStatus Weaver::getConfig(WeaverConfig* out_config) { - (void)out_config; + *out_config = {16, 16, 16}; return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus Weaver::read(int32_t in_slotId, const std::vector& in_key, WeaverReadResponse* out_response) { - (void)in_slotId; - (void)in_key; - (void)out_response; + + if (in_slotId > 15 || in_key.size() > 16) { + *out_response = {0, {}}; + return ndk::ScopedAStatus(AStatus_fromServiceSpecificError(Weaver::STATUS_FAILED)); + } + + if (slot_array[in_slotId].key != in_key) { + *out_response = {0, {}}; + return ndk::ScopedAStatus(AStatus_fromServiceSpecificError(Weaver::STATUS_INCORRECT_KEY)); + } + + *out_response = {0, slot_array[in_slotId].value}; + return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus Weaver::write(int32_t in_slotId, const std::vector& in_key, const std::vector& in_value) { - (void)in_slotId; - (void)in_key; - (void)in_value; + + if (in_slotId > 15 || in_key.size() > 16 || in_value.size() > 16) + return ::ndk::ScopedAStatus::fromStatus(STATUS_FAILED_TRANSACTION); + + slot_array[in_slotId].key = in_key; + slot_array[in_slotId].value = in_value; + return ::ndk::ScopedAStatus::ok(); }