From ed5d92cc7cdaf07bf7e97cc7894f3147cd055b73 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Wed, 24 Jan 2018 00:22:02 +0000 Subject: [PATCH] Add new vibrator effects. Add new effects for pop, thud and heavy click, as well as constants to play back pre-defined ringtone effects. Bug: 64185677 Bug: 64184692 Test: run vts --skip-all-system-status-check --skip-preconditions --primary-abi-only --module VtsHalVibratorV1_2TargetTest Change-Id: I4baae73e1471208f9f54bb1c03da8c27ca6b0ee1 --- vibrator/1.2/Android.bp | 23 ++++++ vibrator/1.2/IVibrator.hal | 37 ++++++++++ vibrator/1.2/types.hal | 64 +++++++++++++++++ vibrator/1.2/vts/functional/Android.bp | 27 +++++++ .../VtsHalVibratorV1_2TargetTest.cpp | 72 +++++++++++++++++++ 5 files changed, 223 insertions(+) create mode 100644 vibrator/1.2/Android.bp create mode 100644 vibrator/1.2/IVibrator.hal create mode 100644 vibrator/1.2/types.hal create mode 100644 vibrator/1.2/vts/functional/Android.bp create mode 100644 vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp diff --git a/vibrator/1.2/Android.bp b/vibrator/1.2/Android.bp new file mode 100644 index 0000000000..88192c18b3 --- /dev/null +++ b/vibrator/1.2/Android.bp @@ -0,0 +1,23 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.vibrator@1.2", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "types.hal", + "IVibrator.hal", + ], + interfaces: [ + "android.hardware.vibrator@1.0", + "android.hardware.vibrator@1.1", + "android.hidl.base@1.0", + ], + types: [ + "Effect", + ], + gen_java: true, +} + diff --git a/vibrator/1.2/IVibrator.hal b/vibrator/1.2/IVibrator.hal new file mode 100644 index 0000000000..7244da1b42 --- /dev/null +++ b/vibrator/1.2/IVibrator.hal @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2018 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.vibrator@1.2; + +import @1.0::EffectStrength; +import @1.0::Status; +import @1.1::IVibrator; + +interface IVibrator extends @1.1::IVibrator { + /** + * Fire off a predefined haptic event. + * + * @param event The type of haptic event to trigger. + * @return status Whether the effect was successfully performed or not. Must + * return Status::UNSUPPORTED_OPERATION is the effect is not supported. + * @return lengthMs The length of time the event is expected to take in + * milliseconds. This doesn't need to be perfectly accurate, but should be a reasonable + * approximation. Should be a positive, non-zero value if the returned status is Status::OK, + * and set to 0 otherwise. + */ + perform_1_2(Effect effect, EffectStrength strength) + generates (Status status, uint32_t lengthMs); +}; diff --git a/vibrator/1.2/types.hal b/vibrator/1.2/types.hal new file mode 100644 index 0000000000..7604f2cea0 --- /dev/null +++ b/vibrator/1.2/types.hal @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2018 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.vibrator@1.2; + +import @1.1::Effect_1_1; + +// Note that while the previous type had a version suffix, this type does not. This is because the +// versions are already present in the namespace and thus don't need to also be embedded in the +// name of the type. +enum Effect : @1.1::Effect_1_1 { + /** + * A thud effect. + * + * This effect should solid feeling bump, like the depression of a heavy mechanical button. + */ + THUD, + /** + * A pop effect. + * + * A short, quick burst effect. + */ + POP, + + /** + * A heavy click effect. + * + * This should produce a sharp striking sensation, like a click but stronger. + */ + HEAVY_CLICK, + + /** + * Ringtone patterns. They may correspond with the device's ringtone audio, or may just be a + * pattern that can be played as a ringtone with any audio, depending on the device. + */ + RINGTONE_1, + RINGTONE_2, + RINGTONE_3, + RINGTONE_4, + RINGTONE_5, + RINGTONE_6, + RINGTONE_7, + RINGTONE_8, + RINGTONE_9, + RINGTONE_10, + RINGTONE_11, + RINGTONE_12, + RINGTONE_13, + RINGTONE_14, + RINGTONE_15, +}; diff --git a/vibrator/1.2/vts/functional/Android.bp b/vibrator/1.2/vts/functional/Android.bp new file mode 100644 index 0000000000..3a4e2efdb5 --- /dev/null +++ b/vibrator/1.2/vts/functional/Android.bp @@ -0,0 +1,27 @@ +// +// Copyright (C) 2018 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: "VtsHalVibratorV1_2TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalVibratorV1_2TargetTest.cpp"], + static_libs: [ + "android.hardware.vibrator@1.0", + "android.hardware.vibrator@1.1", + "android.hardware.vibrator@1.2", + ], +} + diff --git a/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp b/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp new file mode 100644 index 0000000000..d07d1b78e2 --- /dev/null +++ b/vibrator/1.2/vts/functional/VtsHalVibratorV1_2TargetTest.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2018 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. + */ + +#define LOG_TAG "vibrator_hidl_hal_test" + +#include +#include +#include +#include +#include +#include + +using ::android::hardware::vibrator::V1_0::Status; +using ::android::hardware::vibrator::V1_0::EffectStrength; +using ::android::hardware::vibrator::V1_2::Effect; +using ::android::hardware::vibrator::V1_2::IVibrator; +using ::android::hardware::hidl_enum_iterator; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +// The main test class for VIBRATOR HIDL HAL 1.2. +class VibratorHidlTest_1_2 : public ::testing::VtsHalHidlTargetTestBase { + public: + virtual void SetUp() override { + vibrator = ::testing::VtsHalHidlTargetTestBase::getService(); + ASSERT_NE(vibrator, nullptr); + } + + virtual void TearDown() override {} + + sp vibrator; +}; + +static void validatePerformEffect(Status status, uint32_t lengthMs) { + ASSERT_TRUE(status == Status::OK || status == Status::UNSUPPORTED_OPERATION); + if (status == Status::OK) { + ASSERT_GT(lengthMs, static_cast(0)) + << "Effects that return OK must return a non-zero duration"; + } else { + ASSERT_EQ(lengthMs, static_cast(0)) + << "Effects that return UNSUPPORTED_OPERATION must have a duration of zero"; + } +} + +TEST_F(VibratorHidlTest_1_2, PerformEffect_1_2) { + for (const auto& effect : hidl_enum_iterator()) { + for (const auto& strength : hidl_enum_iterator()) { + vibrator->perform_1_2(effect, strength, validatePerformEffect); + } + } +} + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + return status; +}