diff options
author | Andrew Scull <ascull@google.com> | 2017-06-13 10:44:55 +0100 |
---|---|---|
committer | Andrew Scull <ascull@google.com> | 2017-06-27 10:36:11 +0100 |
commit | 3aee4e9e3f3dbd7d4a6e6bd6ba816773a4e4c817 (patch) | |
tree | 46408f978155ee04b7c9a7bbee34e872c8719582 /oemlock/1.0/vts | |
parent | 2d4b941faed83e539839b60d716f303a78a662e1 (diff) | |
download | android_hardware_interfaces-3aee4e9e3f3dbd7d4a6e6bd6ba816773a4e4c817.tar.gz android_hardware_interfaces-3aee4e9e3f3dbd7d4a6e6bd6ba816773a4e4c817.tar.bz2 android_hardware_interfaces-3aee4e9e3f3dbd7d4a6e6bd6ba816773a4e4c817.zip |
OemLock functional VTS test.
Bug: 37530310
Test: VtsHalOemLockV1_0TargetTest
Change-Id: I07adb187f9bde236e2c92f423936089f4cb37b24
Diffstat (limited to 'oemlock/1.0/vts')
-rw-r--r-- | oemlock/1.0/vts/functional/Android.bp | 36 | ||||
-rw-r--r-- | oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp | 189 |
2 files changed, 225 insertions, 0 deletions
diff --git a/oemlock/1.0/vts/functional/Android.bp b/oemlock/1.0/vts/functional/Android.bp new file mode 100644 index 000000000..a13b3dc71 --- /dev/null +++ b/oemlock/1.0/vts/functional/Android.bp @@ -0,0 +1,36 @@ +// +// Copyright (C) 2016 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: "VtsHalOemLockV1_0TargetTest", + defaults: ["hidl_defaults"], + srcs: ["VtsHalOemLockV1_0TargetTest.cpp"], + shared_libs: [ + "libbase", + "liblog", + "libcutils", + "libhidlbase", + "libhidltransport", + "libnativehelper", + "libutils", + "android.hardware.oemlock@1.0", + ], + static_libs: ["VtsHalHidlTargetTestBase"], + cflags: [ + "-O0", + "-g", + ], +} diff --git a/oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp b/oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp new file mode 100644 index 000000000..a924feca3 --- /dev/null +++ b/oemlock/1.0/vts/functional/VtsHalOemLockV1_0TargetTest.cpp @@ -0,0 +1,189 @@ +/* + * 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/oemlock/1.0/IOemLock.h> + +#include <VtsHalHidlTargetTestBase.h> + +using ::android::hardware::oemlock::V1_0::IOemLock; +using ::android::hardware::oemlock::V1_0::OemLockStatus; +using ::android::hardware::oemlock::V1_0::OemLockSecureStatus; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::sp; + +struct OemLockHidlTest : public ::testing::VtsHalHidlTargetTestBase { + virtual void SetUp() override { + oemlock = ::testing::VtsHalHidlTargetTestBase::getService<IOemLock>(); + ASSERT_NE(oemlock, nullptr); + } + + virtual void TearDown() override {} + + sp<IOemLock> oemlock; +}; + +/* + * Check the name can be retrieved + */ +TEST_F(OemLockHidlTest, GetName) { + std::string name; + OemLockStatus status; + + bool callbackCalled = false; + const auto ret = oemlock->getName([&](OemLockStatus s, hidl_string n) { + callbackCalled = true; + status = s; + name = n.c_str(); + }); + + ASSERT_TRUE(ret.isOk()); + ASSERT_TRUE(callbackCalled); + EXPECT_EQ(status, OemLockStatus::OK); + // Any value acceptable +}; + +/* + * Check the unlock allowed by device state can be queried + */ +TEST_F(OemLockHidlTest, QueryUnlockAllowedByDevice) { + bool allowed; + OemLockStatus status; + + bool callbackCalled = false; + const auto ret = oemlock->isOemUnlockAllowedByDevice([&](OemLockStatus s, bool a) { + callbackCalled = true; + status = s; + allowed = a; + }); + + ASSERT_TRUE(ret.isOk()); + ASSERT_TRUE(callbackCalled); + EXPECT_EQ(status, OemLockStatus::OK); + // Any value acceptable +} + +/* + * Check unlock allowed by device state can be toggled + */ +TEST_F(OemLockHidlTest, AllowedByDeviceCanBeToggled) { + bool allowed; + OemLockStatus status; + + auto getAllowedCallback = [&](OemLockStatus s, bool a) { + status = s; + allowed = a; + }; + + // Get the original state so it can be restored + const auto get_ret = oemlock->isOemUnlockAllowedByDevice(getAllowedCallback); + ASSERT_TRUE(get_ret.isOk()); + ASSERT_EQ(status, OemLockStatus::OK); + const bool originallyAllowed = allowed; + + // Toggle the state + const auto set_ret = oemlock->setOemUnlockAllowedByDevice(!originallyAllowed); + ASSERT_TRUE(set_ret.isOk()); + ASSERT_EQ(set_ret, OemLockStatus::OK); + const auto check_set_ret = oemlock->isOemUnlockAllowedByDevice(getAllowedCallback); + ASSERT_TRUE(check_set_ret.isOk()); + ASSERT_EQ(status, OemLockStatus::OK); + ASSERT_EQ(allowed, !originallyAllowed); + + // Restore the state + const auto restore_ret = oemlock->setOemUnlockAllowedByDevice(originallyAllowed); + ASSERT_TRUE(restore_ret.isOk()); + ASSERT_EQ(restore_ret, OemLockStatus::OK); + const auto check_restore_ret = oemlock->isOemUnlockAllowedByDevice(getAllowedCallback); + ASSERT_TRUE(check_restore_ret.isOk()); + ASSERT_EQ(status, OemLockStatus::OK); + ASSERT_EQ(allowed, originallyAllowed); +}; + +/* + * Check the unlock allowed by device state can be queried + */ +TEST_F(OemLockHidlTest, QueryUnlockAllowedByCarrier) { + bool allowed; + OemLockStatus status; + + bool callbackCalled = false; + const auto ret = oemlock->isOemUnlockAllowedByCarrier([&](OemLockStatus s, bool a) { + callbackCalled = true; + status = s; + allowed = a; + }); + + ASSERT_TRUE(ret.isOk()); + ASSERT_TRUE(callbackCalled); + EXPECT_EQ(status, OemLockStatus::OK); + // Any value acceptable +} + +/* + * Attempt to check unlock allowed by carrier can be toggled + * + * The implementation may involve a signature which cannot be tested here. That + * is a valid implementation so the test will pass. If there is no signature + * required, the test will toggle the value. + */ +TEST_F(OemLockHidlTest, CarrierUnlock) { + const hidl_vec<uint8_t> noSignature = {}; + bool allowed; + OemLockStatus status; + + auto getAllowedCallback = [&](OemLockStatus s, bool a) { + status = s; + allowed = a; + }; + + // Get the original state so it can be restored + const auto get_ret = oemlock->isOemUnlockAllowedByCarrier(getAllowedCallback); + ASSERT_TRUE(get_ret.isOk()); + ASSERT_EQ(status, OemLockStatus::OK); + const bool originallyAllowed = allowed; + + if (originallyAllowed) { + // Only applied to locked devices + return; + } + + // Toggle the state + const auto set_ret = oemlock->setOemUnlockAllowedByCarrier(!originallyAllowed, noSignature); + ASSERT_TRUE(set_ret.isOk()); + ASSERT_NE(set_ret, OemLockSecureStatus::FAILED); + const auto check_set_ret = oemlock->isOemUnlockAllowedByCarrier(getAllowedCallback); + ASSERT_TRUE(check_set_ret.isOk()); + ASSERT_EQ(status, OemLockStatus::OK); + + if (set_ret == OemLockSecureStatus::INVALID_SIGNATURE) { + // Signature is required so we cannot toggle the value in the test, but this is allowed + ASSERT_EQ(allowed, originallyAllowed); + return; + } + + ASSERT_EQ(set_ret, OemLockSecureStatus::OK); + ASSERT_EQ(allowed, !originallyAllowed); + + // Restore the state + const auto restore_ret = oemlock->setOemUnlockAllowedByCarrier(originallyAllowed, noSignature); + ASSERT_TRUE(restore_ret.isOk()); + ASSERT_EQ(restore_ret, OemLockSecureStatus::OK); + const auto check_restore_ret = oemlock->isOemUnlockAllowedByCarrier(getAllowedCallback); + ASSERT_TRUE(check_restore_ret.isOk()); + ASSERT_EQ(status, OemLockStatus::OK); + ASSERT_EQ(allowed, originallyAllowed); +}; |