diff options
author | Jack Yu <jackcwyu@google.com> | 2019-12-17 16:11:40 +0800 |
---|---|---|
committer | George Chang <georgekgchang@google.com> | 2020-01-17 14:06:27 +0000 |
commit | 0d914d8c2a4621638d0b5bd7748b1f935ae6136a (patch) | |
tree | 6c7d247b06b5fc532e5eff9854e38e7a5355375b /secure_element | |
parent | 384eb8a2bb035a1e9bf0a56d17e51670f1b09d6d (diff) |
Add android.hardware.secure_element@1.2
Test: None
Bug: 142495673
Change-Id: Ie0f3e87d58047b76ea47990a49d3eac745967255
Diffstat (limited to 'secure_element')
-rw-r--r-- | secure_element/1.2/Android.bp | 18 | ||||
-rw-r--r-- | secure_element/1.2/ISecureElement.hal | 35 | ||||
-rw-r--r-- | secure_element/1.2/vts/functional/Android.bp | 27 | ||||
-rw-r--r-- | secure_element/1.2/vts/functional/VtsHalSecureElementV1_2TargetTest.cpp | 101 |
4 files changed, 181 insertions, 0 deletions
diff --git a/secure_element/1.2/Android.bp b/secure_element/1.2/Android.bp new file mode 100644 index 0000000000..e134771880 --- /dev/null +++ b/secure_element/1.2/Android.bp @@ -0,0 +1,18 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.secure_element@1.2", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "ISecureElement.hal", + ], + interfaces: [ + "android.hardware.secure_element@1.0", + "android.hardware.secure_element@1.1", + "android.hidl.base@1.0", + ], + gen_java: true, +} diff --git a/secure_element/1.2/ISecureElement.hal b/secure_element/1.2/ISecureElement.hal new file mode 100644 index 0000000000..16cc5775b5 --- /dev/null +++ b/secure_element/1.2/ISecureElement.hal @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 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.secure_element@1.2; + +import @1.1::ISecureElementHalCallback; +import @1.1::ISecureElement; +import @1.0::SecureElementStatus; + +interface ISecureElement extends @1.1::ISecureElement { + /** + * Reset the Secure Element. + * + * HAL should trigger reset to the secure element. It could hardware power cycle or + * a soft reset depends on hardware design. + * HAL service must send onStateChange() with connected equal to true + * after resetting and all the re-initialization has been successfully completed. + * + * @return SecureElementStatus::SUCCESS on success and SecureElementStatus::FAILED on error. + */ + reset() generates (SecureElementStatus status); +}; diff --git a/secure_element/1.2/vts/functional/Android.bp b/secure_element/1.2/vts/functional/Android.bp new file mode 100644 index 0000000000..a1732108ab --- /dev/null +++ b/secure_element/1.2/vts/functional/Android.bp @@ -0,0 +1,27 @@ +// +// Copyright (C) 2019 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: "VtsHalSecureElementV1_2TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalSecureElementV1_2TargetTest.cpp"], + static_libs: [ + "android.hardware.secure_element@1.0", + "android.hardware.secure_element@1.1", + "android.hardware.secure_element@1.2", + ], + test_suites: ["general-tests", "vts-core"], +} diff --git a/secure_element/1.2/vts/functional/VtsHalSecureElementV1_2TargetTest.cpp b/secure_element/1.2/vts/functional/VtsHalSecureElementV1_2TargetTest.cpp new file mode 100644 index 0000000000..98e45021d9 --- /dev/null +++ b/secure_element/1.2/vts/functional/VtsHalSecureElementV1_2TargetTest.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2019 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 <string> + +#define LOG_TAG "secure_element_hidl_hal_test" +#include <android-base/logging.h> + +#include <android/hardware/secure_element/1.0/types.h> +#include <android/hardware/secure_element/1.1/ISecureElementHalCallback.h> +#include <android/hardware/secure_element/1.2/ISecureElement.h> +#include <gtest/gtest.h> +#include <hidl/GtestPrinter.h> +#include <hidl/ServiceManagement.h> + +#include <VtsHalHidlTargetCallbackBase.h> + +using ::android::sp; +using ::android::hardware::hidl_string; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::secure_element::V1_0::SecureElementStatus; +using ::android::hardware::secure_element::V1_1::ISecureElementHalCallback; +using ::android::hardware::secure_element::V1_2::ISecureElement; + +constexpr char kCallbackNameOnStateChange[] = "onStateChange"; + +class SecureElementCallbackArgs { + public: + bool state_; + hidl_string reason_; +}; + +class SecureElementHalCallback + : public ::testing::VtsHalHidlTargetCallbackBase<SecureElementCallbackArgs>, + public ISecureElementHalCallback { + public: + virtual ~SecureElementHalCallback() = default; + + Return<void> onStateChange_1_1(bool state, const hidl_string& reason) override { + SecureElementCallbackArgs args; + args.state_ = state; + args.reason_ = reason; + NotifyFromCallback(kCallbackNameOnStateChange, args); + return Void(); + }; + + Return<void> onStateChange(__attribute__((unused)) bool state) override { return Void(); } +}; + +class SecureElementHidlTest : public ::testing::TestWithParam<std::string> { + public: + virtual void SetUp() override { + LOG(INFO) << "get service with name:" << GetParam(); + se_ = ISecureElement::getService(GetParam()); + ASSERT_NE(se_, nullptr); + + se_cb_ = new SecureElementHalCallback(); + ASSERT_NE(se_cb_, nullptr); + se_->init_1_1(se_cb_); + auto res = se_cb_->WaitForCallback(kCallbackNameOnStateChange); + EXPECT_TRUE(res.no_timeout); + EXPECT_TRUE(res.args->state_); + EXPECT_NE(res.args->reason_, ""); + } + + sp<ISecureElement> se_; + sp<SecureElementHalCallback> se_cb_; +}; + +/* + * Reset: + * Calls reset() + * Checks status + * Check onStateChange is received with connected state set to true + */ +TEST_P(SecureElementHidlTest, Reset) { + EXPECT_EQ(SecureElementStatus::SUCCESS, se_->reset()); + + auto res = se_cb_->WaitForCallback(kCallbackNameOnStateChange); + EXPECT_TRUE(res.no_timeout); + EXPECT_TRUE(res.args->state_); +} + +INSTANTIATE_TEST_SUITE_P( + PerInstance, SecureElementHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISecureElement::descriptor)), + android::hardware::PrintInstanceNameToString); |