upload android base code part4
This commit is contained in:
parent
b9e30e05b1
commit
78ea2404cd
23455 changed files with 5250148 additions and 0 deletions
66
android/hardware/interfaces/weaver/1.0/Android.bp
Normal file
66
android/hardware/interfaces/weaver/1.0/Android.bp
Normal file
|
@ -0,0 +1,66 @@
|
|||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
filegroup {
|
||||
name: "android.hardware.weaver@1.0_hal",
|
||||
srcs: [
|
||||
"types.hal",
|
||||
"IWeaver.hal",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.weaver@1.0_genc++",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.weaver@1.0",
|
||||
srcs: [
|
||||
":android.hardware.weaver@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/weaver/1.0/types.cpp",
|
||||
"android/hardware/weaver/1.0/WeaverAll.cpp",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.weaver@1.0_genc++_headers",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.weaver@1.0",
|
||||
srcs: [
|
||||
":android.hardware.weaver@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/weaver/1.0/types.h",
|
||||
"android/hardware/weaver/1.0/hwtypes.h",
|
||||
"android/hardware/weaver/1.0/IWeaver.h",
|
||||
"android/hardware/weaver/1.0/IHwWeaver.h",
|
||||
"android/hardware/weaver/1.0/BnHwWeaver.h",
|
||||
"android/hardware/weaver/1.0/BpHwWeaver.h",
|
||||
"android/hardware/weaver/1.0/BsWeaver.h",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.weaver@1.0",
|
||||
defaults: ["hidl-module-defaults"],
|
||||
generated_sources: ["android.hardware.weaver@1.0_genc++"],
|
||||
generated_headers: ["android.hardware.weaver@1.0_genc++_headers"],
|
||||
export_generated_headers: ["android.hardware.weaver@1.0_genc++_headers"],
|
||||
vendor_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
],
|
||||
export_shared_lib_headers: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
],
|
||||
}
|
232
android/hardware/interfaces/weaver/1.0/Android.mk
Normal file
232
android/hardware/interfaces/weaver/1.0/Android.mk
Normal file
|
@ -0,0 +1,232 @@
|
|||
# This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.weaver-V1.0-java
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java \
|
||||
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverConfig)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverConfig.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverConfig
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverReadResponse)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverReadResponse.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverReadResponse
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverReadStatus)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverReadStatus.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverReadStatus
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverStatus)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverStatus.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverStatus
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build IWeaver.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/IWeaver.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IWeaver.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::IWeaver
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/IWeaver.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.weaver-V1.0-java-static
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java-static \
|
||||
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverConfig)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverConfig.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverConfig
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverReadResponse)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverReadResponse.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverReadResponse
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverReadStatus)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverReadStatus.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverReadStatus
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (WeaverStatus)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/WeaverStatus.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::types.WeaverStatus
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build IWeaver.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/weaver/V1_0/IWeaver.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IWeaver.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.weaver@1.0::IWeaver
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/IWeaver.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
80
android/hardware/interfaces/weaver/1.0/IWeaver.hal
Normal file
80
android/hardware/interfaces/weaver/1.0/IWeaver.hal
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package android.hardware.weaver@1.0;
|
||||
|
||||
/**
|
||||
* Weaver provides secure storage of secret values that may only be read if the
|
||||
* corresponding key has been presented.
|
||||
*
|
||||
* The storage must be secure as the device's user authentication and encryption
|
||||
* relies on the security of these values. The cardinality of the domains of the
|
||||
* key and value must be suitably large such that they cannot be easily guessed.
|
||||
*
|
||||
* Weaver is structured as an array of slots, each containing a key-value pair.
|
||||
* Slots are uniquely identified by an ID in the range [0, `getConfig().slots`).
|
||||
*/
|
||||
interface IWeaver {
|
||||
/**
|
||||
* Retrieves the config information for this implementation of Weaver.
|
||||
*
|
||||
* The config is static i.e. every invocation returns the same information.
|
||||
*
|
||||
* @return status is OK if the config was successfuly obtained.
|
||||
* @return config data for this implementation of Weaver if status is OK,
|
||||
* otherwise undefined.
|
||||
*/
|
||||
getConfig() generates (WeaverStatus status, WeaverConfig config);
|
||||
|
||||
/**
|
||||
* Overwrites the identified slot with the provided key and value.
|
||||
*
|
||||
* The new values are written regardless of the current state of the slot in
|
||||
* order to remain idempotent.
|
||||
*
|
||||
* @param slotId of the slot to write to.
|
||||
* @param key to write to the slot.
|
||||
* @param value to write to slot.
|
||||
* @return status is OK if the write was successfully completed.
|
||||
*/
|
||||
write(uint32_t slotId, vec<uint8_t> key, vec<uint8_t> value)
|
||||
generates (WeaverStatus status);
|
||||
|
||||
/**
|
||||
* Attempts to retrieve the value stored in the identified slot.
|
||||
*
|
||||
* The value is only returned if the provided key matches the key stored in
|
||||
* the slot. The value is never returned if the wrong key is provided.
|
||||
*
|
||||
* Throttling must be used to limit the frequency of failed read attempts.
|
||||
* The value is only returned when throttling is not active, even if the
|
||||
* correct key is provided. If called when throttling is active, the time
|
||||
* until the next attempt can be made is returned.
|
||||
*
|
||||
* @param slotId of the slot to read from.
|
||||
* @param key that is stored in the slot.
|
||||
* @return status is OK if the value was successfully read, INCORRECT_KEY if
|
||||
* the key does not match the key in the slot, THROTTLE if
|
||||
* throttling is active or FAILED if the read was unsuccessful for
|
||||
* another reason.
|
||||
* @return readResponse contains the value read and the timeout to wait
|
||||
* before making the next request. If the status is OK, value is set
|
||||
* to the value in the slot and timeout is 0. Otherwise, value is
|
||||
* empty and timeout is set accordingly.
|
||||
*/
|
||||
read(uint32_t slotId, vec<uint8_t> key)
|
||||
generates (WeaverReadStatus status,
|
||||
WeaverReadResponse readResponse);
|
||||
};
|
42
android/hardware/interfaces/weaver/1.0/types.hal
Normal file
42
android/hardware/interfaces/weaver/1.0/types.hal
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package android.hardware.weaver@1.0;
|
||||
|
||||
enum WeaverStatus : uint32_t {
|
||||
OK,
|
||||
FAILED,
|
||||
};
|
||||
|
||||
struct WeaverConfig {
|
||||
/** The number of slots available. */
|
||||
uint32_t slots;
|
||||
/** The number of bytes used for a key. */
|
||||
uint32_t keySize;
|
||||
/** The number of bytes used for a value. */
|
||||
uint32_t valueSize;
|
||||
};
|
||||
|
||||
enum WeaverReadStatus : WeaverStatus {
|
||||
INCORRECT_KEY,
|
||||
THROTTLE,
|
||||
};
|
||||
|
||||
struct WeaverReadResponse {
|
||||
/** The time to wait, in milliseconds, before making the next request. */
|
||||
uint32_t timeout;
|
||||
/** The value read from the slot or empty if the value was not read. */
|
||||
vec<uint8_t> value;
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
cc_test {
|
||||
name: "VtsHalWeaverV1_0TargetTest",
|
||||
defaults: ["VtsHalTargetTestDefaults"],
|
||||
srcs: ["VtsHalWeaverV1_0TargetTest.cpp"],
|
||||
static_libs: ["android.hardware.weaver@1.0"],
|
||||
}
|
|
@ -0,0 +1,336 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <android/hardware/weaver/1.0/IWeaver.h>
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
|
||||
using ::android::hardware::weaver::V1_0::IWeaver;
|
||||
using ::android::hardware::weaver::V1_0::WeaverConfig;
|
||||
using ::android::hardware::weaver::V1_0::WeaverReadStatus;
|
||||
using ::android::hardware::weaver::V1_0::WeaverReadResponse;
|
||||
using ::android::hardware::weaver::V1_0::WeaverStatus;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::sp;
|
||||
|
||||
const std::vector<uint8_t> KEY{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||
const std::vector<uint8_t> WRONG_KEY{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
const std::vector<uint8_t> VALUE{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
|
||||
const std::vector<uint8_t> OTHER_VALUE{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 255, 255};
|
||||
|
||||
struct WeaverHidlTest : public ::testing::VtsHalHidlTargetTestBase {
|
||||
virtual void SetUp() override {
|
||||
weaver = ::testing::VtsHalHidlTargetTestBase::getService<IWeaver>();
|
||||
ASSERT_NE(weaver, nullptr);
|
||||
}
|
||||
|
||||
virtual void TearDown() override {}
|
||||
|
||||
sp<IWeaver> weaver;
|
||||
};
|
||||
|
||||
/*
|
||||
* Checks config values are suitably large
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, GetConfig) {
|
||||
WeaverStatus status;
|
||||
WeaverConfig config;
|
||||
|
||||
bool callbackCalled = false;
|
||||
auto ret = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
callbackCalled = true;
|
||||
status = s;
|
||||
config = c;
|
||||
});
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
EXPECT_GE(config.slots, 16u);
|
||||
EXPECT_GE(config.keySize, 16u);
|
||||
EXPECT_GE(config.valueSize, 16u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the config twice and checks they are the same
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, GettingConfigMultipleTimesGivesSameResult) {
|
||||
WeaverConfig config1;
|
||||
WeaverConfig config2;
|
||||
|
||||
WeaverStatus status;
|
||||
bool callbackCalled = false;
|
||||
auto ret = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
callbackCalled = true;
|
||||
status = s;
|
||||
config1 = c;
|
||||
});
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
callbackCalled = false;
|
||||
ret = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
callbackCalled = true;
|
||||
status = s;
|
||||
config2 = c;
|
||||
});
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
EXPECT_EQ(config1, config2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the number of slots from the config and writes a key and value to the last one
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, WriteToLastSlot) {
|
||||
WeaverStatus status;
|
||||
WeaverConfig config;
|
||||
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
status = s;
|
||||
config = c;
|
||||
});
|
||||
ASSERT_TRUE(configRet.isOk());
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
const uint32_t lastSlot = config.slots - 1;
|
||||
const auto writeRet = weaver->write(lastSlot, KEY, VALUE);
|
||||
ASSERT_TRUE(writeRet.isOk());
|
||||
ASSERT_EQ(writeRet, WeaverStatus::OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes a key and value to a slot
|
||||
* Reads the slot with the same key and receives the value that was previously written
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, WriteFollowedByReadGivesTheSameValue) {
|
||||
constexpr uint32_t slotId = 0;
|
||||
const auto ret = weaver->write(slotId, KEY, VALUE);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
ASSERT_EQ(ret, WeaverStatus::OK);
|
||||
|
||||
bool callbackCalled = false;
|
||||
WeaverReadStatus status;
|
||||
std::vector<uint8_t> readValue;
|
||||
uint32_t timeout;
|
||||
const auto readRet = weaver->read(slotId, KEY, [&](WeaverReadStatus s, WeaverReadResponse r) {
|
||||
callbackCalled = true;
|
||||
status = s;
|
||||
readValue = r.value;
|
||||
timeout = r.timeout;
|
||||
});
|
||||
ASSERT_TRUE(readRet.isOk());
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_EQ(status, WeaverReadStatus::OK);
|
||||
EXPECT_EQ(readValue, VALUE);
|
||||
EXPECT_EQ(timeout, 0u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes a key and value to a slot
|
||||
* Overwrites the slot with a new key and value
|
||||
* Reads the slot with the new key and receives the new value
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, OverwritingSlotUpdatesTheValue) {
|
||||
constexpr uint32_t slotId = 0;
|
||||
const auto initialWriteRet = weaver->write(slotId, WRONG_KEY, VALUE);
|
||||
ASSERT_TRUE(initialWriteRet.isOk());
|
||||
ASSERT_EQ(initialWriteRet, WeaverStatus::OK);
|
||||
|
||||
const auto overwriteRet = weaver->write(slotId, KEY, OTHER_VALUE);
|
||||
ASSERT_TRUE(overwriteRet.isOk());
|
||||
ASSERT_EQ(overwriteRet, WeaverStatus::OK);
|
||||
|
||||
bool callbackCalled = false;
|
||||
WeaverReadStatus status;
|
||||
std::vector<uint8_t> readValue;
|
||||
uint32_t timeout;
|
||||
const auto readRet = weaver->read(slotId, KEY, [&](WeaverReadStatus s, WeaverReadResponse r) {
|
||||
callbackCalled = true;
|
||||
status = s;
|
||||
readValue = r.value;
|
||||
timeout = r.timeout;
|
||||
});
|
||||
ASSERT_TRUE(readRet.isOk());
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_EQ(status, WeaverReadStatus::OK);
|
||||
EXPECT_EQ(readValue, OTHER_VALUE);
|
||||
EXPECT_EQ(timeout, 0u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes a key and value to a slot
|
||||
* Reads the slot with a different key so does not receive the value
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, WriteFollowedByReadWithWrongKeyDoesNotGiveTheValue) {
|
||||
constexpr uint32_t slotId = 0;
|
||||
const auto ret = weaver->write(slotId, KEY, VALUE);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
ASSERT_EQ(ret, WeaverStatus::OK);
|
||||
|
||||
bool callbackCalled = false;
|
||||
WeaverReadStatus status;
|
||||
std::vector<uint8_t> readValue;
|
||||
const auto readRet =
|
||||
weaver->read(slotId, WRONG_KEY, [&](WeaverReadStatus s, WeaverReadResponse r) {
|
||||
callbackCalled = true;
|
||||
status = s;
|
||||
readValue = r.value;
|
||||
});
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_TRUE(readRet.isOk());
|
||||
ASSERT_EQ(status, WeaverReadStatus::INCORRECT_KEY);
|
||||
EXPECT_TRUE(readValue.empty());
|
||||
}
|
||||
|
||||
/*
|
||||
* Writing to an invalid slot fails
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, WritingToInvalidSlotFails) {
|
||||
WeaverStatus status;
|
||||
WeaverConfig config;
|
||||
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
status = s;
|
||||
config = c;
|
||||
});
|
||||
ASSERT_TRUE(configRet.isOk());
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
if (config.slots == std::numeric_limits<uint32_t>::max()) {
|
||||
// If there are no invalid slots then pass
|
||||
return;
|
||||
}
|
||||
|
||||
const auto writeRet = weaver->write(config.slots, KEY, VALUE);
|
||||
ASSERT_TRUE(writeRet.isOk());
|
||||
ASSERT_EQ(writeRet, WeaverStatus::FAILED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reading from an invalid slot fails rather than incorrect key
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, ReadingFromInvalidSlotFails) {
|
||||
WeaverStatus status;
|
||||
WeaverConfig config;
|
||||
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
status = s;
|
||||
config = c;
|
||||
});
|
||||
ASSERT_TRUE(configRet.isOk());
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
if (config.slots == std::numeric_limits<uint32_t>::max()) {
|
||||
// If there are no invalid slots then pass
|
||||
return;
|
||||
}
|
||||
|
||||
bool callbackCalled = false;
|
||||
WeaverReadStatus readStatus;
|
||||
std::vector<uint8_t> readValue;
|
||||
uint32_t timeout;
|
||||
const auto readRet =
|
||||
weaver->read(config.slots, KEY, [&](WeaverReadStatus s, WeaverReadResponse r) {
|
||||
callbackCalled = true;
|
||||
readStatus = s;
|
||||
readValue = r.value;
|
||||
timeout = r.timeout;
|
||||
});
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_TRUE(readRet.isOk());
|
||||
ASSERT_EQ(readStatus, WeaverReadStatus::FAILED);
|
||||
EXPECT_TRUE(readValue.empty());
|
||||
EXPECT_EQ(timeout, 0u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writing a key that is too large fails
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, WriteWithTooLargeKeyFails) {
|
||||
WeaverStatus status;
|
||||
WeaverConfig config;
|
||||
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
status = s;
|
||||
config = c;
|
||||
});
|
||||
ASSERT_TRUE(configRet.isOk());
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
std::vector<uint8_t> bigKey(config.keySize + 1);
|
||||
|
||||
constexpr uint32_t slotId = 0;
|
||||
const auto writeRet = weaver->write(slotId, bigKey, VALUE);
|
||||
ASSERT_TRUE(writeRet.isOk());
|
||||
ASSERT_EQ(writeRet, WeaverStatus::FAILED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writing a value that is too large fails
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, WriteWithTooLargeValueFails) {
|
||||
WeaverStatus status;
|
||||
WeaverConfig config;
|
||||
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
status = s;
|
||||
config = c;
|
||||
});
|
||||
ASSERT_TRUE(configRet.isOk());
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
std::vector<uint8_t> bigValue(config.valueSize + 1);
|
||||
|
||||
constexpr uint32_t slotId = 0;
|
||||
const auto writeRet = weaver->write(slotId, KEY, bigValue);
|
||||
ASSERT_TRUE(writeRet.isOk());
|
||||
ASSERT_EQ(writeRet, WeaverStatus::FAILED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reading with a key that is loo large fails
|
||||
*/
|
||||
TEST_F(WeaverHidlTest, ReadWithTooLargeKeyFails) {
|
||||
WeaverStatus status;
|
||||
WeaverConfig config;
|
||||
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
|
||||
status = s;
|
||||
config = c;
|
||||
});
|
||||
ASSERT_TRUE(configRet.isOk());
|
||||
ASSERT_EQ(status, WeaverStatus::OK);
|
||||
|
||||
std::vector<uint8_t> bigKey(config.keySize + 1);
|
||||
|
||||
constexpr uint32_t slotId = 0;
|
||||
bool callbackCalled = false;
|
||||
WeaverReadStatus readStatus;
|
||||
std::vector<uint8_t> readValue;
|
||||
uint32_t timeout;
|
||||
const auto readRet =
|
||||
weaver->read(slotId, bigKey, [&](WeaverReadStatus s, WeaverReadResponse r) {
|
||||
callbackCalled = true;
|
||||
readStatus = s;
|
||||
readValue = r.value;
|
||||
timeout = r.timeout;
|
||||
});
|
||||
ASSERT_TRUE(callbackCalled);
|
||||
ASSERT_TRUE(readRet.isOk());
|
||||
ASSERT_EQ(readStatus, WeaverReadStatus::FAILED);
|
||||
EXPECT_TRUE(readValue.empty());
|
||||
EXPECT_EQ(timeout, 0u);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue