diff options
author | Harpreet "Eli" Sangha <eliptus@google.com> | 2018-12-14 12:06:34 +0900 |
---|---|---|
committer | Harpreet "Eli" Sangha <eliptus@google.com> | 2018-12-25 13:40:38 +0900 |
commit | 1f1532631aab8ad7f042cbd42cd0c79398e6f702 (patch) | |
tree | ef6a155ce687f3354e1fbf84f93d4073e173b214 /vibrator/1.3 | |
parent | 9b1689da743c56239a2ae65804f3ccae87474756 (diff) | |
download | platform_hardware_interfaces-1f1532631aab8ad7f042cbd42cd0c79398e6f702.tar.gz platform_hardware_interfaces-1f1532631aab8ad7f042cbd42cd0c79398e6f702.tar.bz2 platform_hardware_interfaces-1f1532631aab8ad7f042cbd42cd0c79398e6f702.zip |
vibrator: Add Vibrator HAL 1.3
Add API for enabling/disabling external control of vibrator.
Bug: 117835666
Test: Sanity Check Via 'cmd vibrator'
Change-Id: I5342ca9feba1811efcb5483668858db3f70ad686
Signed-off-by: Harpreet "Eli" Sangha <eliptus@google.com>
Diffstat (limited to 'vibrator/1.3')
-rw-r--r-- | vibrator/1.3/Android.bp | 20 | ||||
-rw-r--r-- | vibrator/1.3/IVibrator.hal | 44 | ||||
-rw-r--r-- | vibrator/1.3/vts/functional/Android.bp | 29 | ||||
-rw-r--r-- | vibrator/1.3/vts/functional/VtsHalVibratorV1_3TargetTest.cpp | 81 |
4 files changed, 174 insertions, 0 deletions
diff --git a/vibrator/1.3/Android.bp b/vibrator/1.3/Android.bp new file mode 100644 index 0000000000..28370d6e4d --- /dev/null +++ b/vibrator/1.3/Android.bp @@ -0,0 +1,20 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.vibrator@1.3", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "IVibrator.hal", + ], + interfaces: [ + "android.hardware.vibrator@1.0", + "android.hardware.vibrator@1.1", + "android.hardware.vibrator@1.2", + "android.hidl.base@1.0", + ], + gen_java: true, +} + diff --git a/vibrator/1.3/IVibrator.hal b/vibrator/1.3/IVibrator.hal new file mode 100644 index 0000000000..01c2801720 --- /dev/null +++ b/vibrator/1.3/IVibrator.hal @@ -0,0 +1,44 @@ +/* + * 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.3; + +import @1.0::Status; +import @1.2::IVibrator; + +interface IVibrator extends @1.2::IVibrator { + /** + * Returns whether the vibrator supports control through an alternate interface. + */ + supportsExternalControl() generates (bool supports); + + /** + * Enables/disables control override of vibrator to audio. + * + * When this API is set, the vibrator control should be ceded to audio system + * for haptic audio. While this is enabled, issuing of other commands to control + * the vibrator is unsupported and the resulting behavior is undefined. Amplitude + * control may or may not be supported and is reflected in the return value of + * supportsAmplitudeControl() while this is enabled. When this is disabled, the + * vibrator should resume to an off state. + * + * @param enabled Whether external control should be enabled or disabled. + * @return status Whether the command was successful or not. Must return + * Status::UNSUPPORTED_OPERATION if external control is + * not supported by the device. + */ + setExternalControl(bool enabled) generates (Status status); +}; diff --git a/vibrator/1.3/vts/functional/Android.bp b/vibrator/1.3/vts/functional/Android.bp new file mode 100644 index 0000000000..5b4c8933d2 --- /dev/null +++ b/vibrator/1.3/vts/functional/Android.bp @@ -0,0 +1,29 @@ +// +// 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_3TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["VtsHalVibratorV1_3TargetTest.cpp"], + static_libs: [ + "android.hardware.vibrator@1.0", + "android.hardware.vibrator@1.1", + "android.hardware.vibrator@1.2", + "android.hardware.vibrator@1.3", + ], + test_suites: ["general-tests"], +} + diff --git a/vibrator/1.3/vts/functional/VtsHalVibratorV1_3TargetTest.cpp b/vibrator/1.3/vts/functional/VtsHalVibratorV1_3TargetTest.cpp new file mode 100644 index 0000000000..a67d1dc8c7 --- /dev/null +++ b/vibrator/1.3/vts/functional/VtsHalVibratorV1_3TargetTest.cpp @@ -0,0 +1,81 @@ +/* + * 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. + */ + +#define LOG_TAG "vibrator_hidl_hal_test" + +#include <VtsHalHidlTargetTestBase.h> +#include <VtsHalHidlTargetTestEnvBase.h> +#include <android-base/logging.h> +#include <android/hardware/vibrator/1.0/types.h> +#include <android/hardware/vibrator/1.3/IVibrator.h> +#include <unistd.h> + +using ::android::sp; +using ::android::hardware::vibrator::V1_0::Status; +using ::android::hardware::vibrator::V1_3::IVibrator; + +// Test environment for Vibrator HIDL HAL. +class VibratorHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static VibratorHidlEnvironment* Instance() { + static VibratorHidlEnvironment* instance = new VibratorHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { registerTestService<IVibrator>(); } + + private: + VibratorHidlEnvironment() {} +}; + +// The main test class for VIBRATOR HIDL HAL 1.3. +class VibratorHidlTest_1_3 : public ::testing::VtsHalHidlTargetTestBase { + public: + virtual void SetUp() override { + vibrator = ::testing::VtsHalHidlTargetTestBase::getService<IVibrator>( + VibratorHidlEnvironment::Instance()->getServiceName<IVibrator>()); + ASSERT_NE(vibrator, nullptr); + } + + virtual void TearDown() override {} + + sp<IVibrator> vibrator; +}; + +TEST_F(VibratorHidlTest_1_3, ChangeVibrationalExternalControl) { + if (vibrator->supportsExternalControl()) { + EXPECT_EQ(Status::OK, vibrator->setExternalControl(true)); + sleep(1); + EXPECT_EQ(Status::OK, vibrator->setExternalControl(false)); + sleep(1); + } +} + +TEST_F(VibratorHidlTest_1_3, SetExternalControlReturnUnsupportedOperationIfNotSupported) { + if (!vibrator->supportsExternalControl()) { + EXPECT_EQ(Status::UNSUPPORTED_OPERATION, vibrator->setExternalControl(true)); + } +} + +int main(int argc, char** argv) { + ::testing::AddGlobalTestEnvironment(VibratorHidlEnvironment::Instance()); + ::testing::InitGoogleTest(&argc, argv); + VibratorHidlEnvironment::Instance()->init(&argc, argv); + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + return status; +} |