vibrator: Moved to hardware/google/pixel
Moving Vibrator HIDL from device repository to Pixel common repository
to facilitate source sharing and testing.
Bug: 132131929
Test: PTS, VTS, Manual
Change-Id: I802d5584141ce40ccec91d24074568d8b393d3c7
Signed-off-by: Harpreet "Eli" Sangha <eliptus@google.com>
diff --git a/vibrator/Android.bp b/vibrator/Android.bp
deleted file mode 100644
index c9dff3c..0000000
--- a/vibrator/Android.bp
+++ /dev/null
@@ -1,80 +0,0 @@
-//
-// 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_defaults {
- name: "android.hardware.vibrator@1.2-defaults.drv2624",
- defaults: ["hidl_defaults"],
- relative_install_path: "hw",
- shared_libs: [
- "libhidlbase",
- "libcutils",
- "libhidltransport",
- "liblog",
- "libhwbinder",
- "libutils",
- "libhardware",
- "android.hardware.vibrator@1.0",
- "android.hardware.vibrator@1.1",
- "android.hardware.vibrator@1.2",
- ],
- proprietary: true,
-}
-
-cc_library {
- name: "android.hardware.vibrator@1.2-impl.drv2624",
- defaults: ["android.hardware.vibrator@1.2-defaults.drv2624"],
- srcs: [
- "Hardware.cpp",
- "Vibrator.cpp",
- ],
-}
-
-cc_binary {
- name: "android.hardware.vibrator@1.2-service.drv2624",
- defaults: ["android.hardware.vibrator@1.2-defaults.drv2624"],
- init_rc: ["android.hardware.vibrator@1.2-service.drv2624.rc"],
- vintf_fragments: ["android.hardware.vibrator@1.2-service.drv2624.xml"],
- srcs: ["service.cpp"],
- static_libs: ["android.hardware.vibrator@1.2-impl.drv2624"],
-}
-
-cc_test {
- name: "PtsVibratorHalDrv2624TestSuite",
- defaults: ["android.hardware.vibrator@1.2-defaults.drv2624"],
- srcs: [
- "tests/test-hwapi.cpp",
- "tests/test-hwcal.cpp",
- "tests/test-vibrator.cpp",
- ],
- static_libs: [
- "android.hardware.vibrator@1.2-impl.drv2624",
- "libgmock",
- ],
- shared_libs: [
- "libbase",
- ],
- test_suites: [
- "general-tests",
- "pts",
- ],
- multilib: {
- lib32: {
- suffix: "32",
- },
- lib64: {
- suffix: "64",
- },
- },
-}
diff --git a/vibrator/AndroidTest.xml b/vibrator/AndroidTest.xml
deleted file mode 100644
index 6a8a87d..0000000
--- a/vibrator/AndroidTest.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (c) 2019 Google Inc.
-
- 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.
--->
-<configuration description="Runs PtsVibratorHalDrv2624TestSuite.">
- <option name="test-suite-tag" value="pts" />
- <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
- <option name="append-bitness" value="true" />
- <option name="cleanup" value="true" />
- <option name="push" value="PtsVibratorHalDrv2624TestSuite->/data/local/tmp/PtsVibratorHalDrv2624TestSuite" />
- </target_preparer>
- <test class="com.android.tradefed.testtype.GTest" >
- <option name="module-name" value="PtsVibratorHalDrv2624TestSuite" />
- <option name="native-test-device-path" value="/data/local/tmp" />
- </test>
-</configuration>
diff --git a/vibrator/Hardware.cpp b/vibrator/Hardware.cpp
deleted file mode 100644
index 4a4cfb0..0000000
--- a/vibrator/Hardware.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * 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.
- */
-
-#define LOG_TAG "android.hardware.vibrator@1.2-service.drv2624"
-
-#include "Hardware.h"
-
-#include <log/log.h>
-
-#include <iostream>
-
-#include "utils.h"
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-template <typename T>
-static void fileFromEnv(const char *env, T *outStream, std::string *outName = nullptr) {
- auto file = std::getenv(env);
- auto mode = std::is_base_of_v<std::ostream, T> ? std::ios_base::out : std::ios_base::in;
-
- if (file == nullptr) {
- ALOGE("Failed get env %s", env);
- return;
- }
-
- if (outName != nullptr) {
- *outName = std::string(file);
- }
-
- // Force 'in' mode to prevent file creation
- outStream->open(file, mode | std::ios_base::in);
- if (!*outStream) {
- ALOGE("Failed to open %s:%s (%d): %s", env, file, errno, strerror(errno));
- }
-}
-
-static auto pathsFromEnv(const char *env) {
- std::map<std::string, std::ifstream> ret;
- auto value = std::getenv(env);
-
- if (value == nullptr) {
- return ret;
- }
-
- std::istringstream paths{value};
- std::string path;
-
- while (paths >> path) {
- ret[path].open(path);
- }
-
- return ret;
-}
-
-static std::string trim(const std::string &str, const std::string &whitespace = " \t") {
- const auto str_begin = str.find_first_not_of(whitespace);
- if (str_begin == std::string::npos) {
- return "";
- }
-
- const auto str_end = str.find_last_not_of(whitespace);
- const auto str_range = str_end - str_begin + 1;
-
- return str.substr(str_begin, str_range);
-}
-
-static void unpack(std::istream &stream, uint32_t *value) {
- stream >> *value;
-}
-
-static void unpack(std::istream &stream, std::string *value) {
- *value = std::string(std::istreambuf_iterator(stream), {});
- stream.setstate(std::istream::eofbit);
-}
-
-HwApi::HwApi() {
- fileFromEnv("AUTOCAL_FILEPATH", &mAutocal, &mNames[&mAutocal]);
- fileFromEnv("OL_LRA_PERIOD_FILEPATH", &mOlLraPeriod, &mNames[&mOlLraPeriod]);
- fileFromEnv("ACTIVATE_PATH", &mActivate, &mNames[&mActivate]);
- fileFromEnv("DURATION_PATH", &mDuration, &mNames[&mDuration]);
- fileFromEnv("STATE_PATH", &mState, &mNames[&mState]);
- fileFromEnv("RTP_INPUT_PATH", &mRtpInput, &mNames[&mRtpInput]);
- fileFromEnv("MODE_PATH", &mMode, &mNames[&mMode]);
- fileFromEnv("SEQUENCER_PATH", &mSequencer, &mNames[&mSequencer]);
- fileFromEnv("SCALE_PATH", &mScale, &mNames[&mScale]);
- fileFromEnv("CTRL_LOOP_PATH", &mCtrlLoop, &mNames[&mCtrlLoop]);
- fileFromEnv("LP_TRIGGER_PATH", &mLpTrigger, &mNames[&mLpTrigger]);
-}
-
-std::unique_ptr<HwApi> HwApi::Create() {
- auto hwapi = std::unique_ptr<HwApi>(new HwApi());
-
- // the following streams are required
- if (!hwapi->mActivate.is_open() || !hwapi->mDuration.is_open() || !hwapi->mState.is_open()) {
- return nullptr;
- }
-
- return hwapi;
-}
-
-template <typename T>
-bool HwApi::has(const T &stream) {
- return !!stream;
-}
-
-template <typename T, typename U>
-bool HwApi::get(T *value, U *stream) {
- bool ret;
- stream->seekg(0);
- *stream >> *value;
- if (!(ret = !!*stream)) {
- ALOGE("Failed to read %s (%d): %s", mNames[stream].c_str(), errno, strerror(errno));
- }
- stream->clear();
- return ret;
-}
-
-template <typename T, typename U>
-bool HwApi::set(const T &value, U *stream) {
- using utils::operator<<;
- bool ret;
- *stream << value << std::endl;
- if (!(ret = !!*stream)) {
- ALOGE("Failed to write %s (%d): %s", mNames[stream].c_str(), errno, strerror(errno));
- stream->clear();
- }
- return ret;
-}
-
-void HwApi::debug(int fd) {
- dprintf(fd, "Kernel:\n");
-
- for (auto &entry : pathsFromEnv("HWAPI_DEBUG_PATHS")) {
- auto &path = entry.first;
- auto &stream = entry.second;
- std::string line;
-
- dprintf(fd, " %s:\n", path.c_str());
- while (std::getline(stream, line)) {
- dprintf(fd, " %s\n", line.c_str());
- }
- }
-}
-
-HwCal::HwCal() {
- std::ifstream calfile;
- auto propertyPrefix = std::getenv("PROPERTY_PREFIX");
-
- if (propertyPrefix != NULL) {
- mPropertyPrefix = std::string(propertyPrefix);
- } else {
- ALOGE("Failed get property prefix!");
- }
-
- fileFromEnv("CALIBRATION_FILEPATH", &calfile);
-
- for (std::string line; std::getline(calfile, line);) {
- if (line.empty() || line[0] == '#') {
- continue;
- }
- std::istringstream is_line(line);
- std::string key, value;
- if (std::getline(is_line, key, ':') && std::getline(is_line, value)) {
- mCalData[trim(key)] = trim(value);
- }
- }
-}
-
-template <typename T>
-bool HwCal::get(const char *key, T *value) {
- auto it = mCalData.find(key);
- if (it == mCalData.end()) {
- ALOGE("Missing %s config!", key);
- return false;
- }
- std::stringstream stream{it->second};
- unpack(stream, value);
- if (!stream || !stream.eof()) {
- ALOGE("Invalid %s config!", key);
- return false;
- }
- return true;
-}
-
-void HwCal::debug(int fd) {
- std::ifstream stream;
- std::string path;
- std::string line;
- struct context {
- HwCal *obj;
- int fd;
- } context{this, fd};
-
- dprintf(fd, "Properties:\n");
-
- property_list(
- [](const char *key, const char *value, void *cookie) {
- struct context *context = static_cast<struct context *>(cookie);
- HwCal *obj = context->obj;
- int fd = context->fd;
- const std::string expect{obj->mPropertyPrefix};
- const std::string actual{key, std::min(strlen(key), expect.size())};
- if (actual == expect) {
- dprintf(fd, " %s:\n", key);
- dprintf(fd, " %s\n", value);
- }
- },
- &context);
-
- dprintf(fd, "\n");
-
- dprintf(fd, "Persist:\n");
-
- fileFromEnv("CALIBRATION_FILEPATH", &stream, &path);
-
- dprintf(fd, " %s:\n", path.c_str());
- while (std::getline(stream, line)) {
- dprintf(fd, " %s\n", line.c_str());
- }
-}
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
diff --git a/vibrator/Hardware.h b/vibrator/Hardware.h
deleted file mode 100644
index 4b1e1f4..0000000
--- a/vibrator/Hardware.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.
- */
-#ifndef ANDROID_HARDWARE_VIBRATOR_HARDWARE_H
-#define ANDROID_HARDWARE_VIBRATOR_HARDWARE_H
-
-#include <cutils/properties.h>
-
-#include "Vibrator.h"
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-class HwApi : public Vibrator::HwApi {
- public:
- static std::unique_ptr<HwApi> Create();
- bool setAutocal(std::string value) override { return set(value, &mAutocal); }
- bool setOlLraPeriod(uint32_t value) override { return set(value, &mOlLraPeriod); }
- bool setActivate(bool value) override { return set(value, &mActivate); }
- bool setDuration(uint32_t value) override { return set(value, &mDuration); }
- bool setState(bool value) override { return set(value, &mState); }
- bool hasRtpInput() override { return has(mRtpInput); }
- bool setRtpInput(int8_t value) override { return set(value, &mRtpInput); }
- bool setMode(std::string value) override { return set(value, &mMode); }
- bool setSequencer(std::string value) override { return set(value, &mSequencer); }
- bool setScale(uint8_t value) override { return set(value, &mScale); }
- bool setCtrlLoop(bool value) override { return set(value, &mCtrlLoop); }
- bool setLpTriggerEffect(uint32_t value) override { return set(value, &mLpTrigger); }
- void debug(int fd) override;
-
- private:
- HwApi();
- template <typename T>
- bool has(const T &stream);
- template <typename T, typename U>
- bool get(T *value, U *stream);
- template <typename T, typename U>
- bool set(const T &value, U *stream);
-
- private:
- std::map<void *, std::string> mNames;
- std::ofstream mAutocal;
- std::ofstream mOlLraPeriod;
- std::ofstream mActivate;
- std::ofstream mDuration;
- std::ofstream mState;
- std::ofstream mRtpInput;
- std::ofstream mMode;
- std::ofstream mSequencer;
- std::ofstream mScale;
- std::ofstream mCtrlLoop;
- std::ofstream mLpTrigger;
-};
-
-class HwCal : public Vibrator::HwCal {
- private:
- static constexpr char AUTOCAL_CONFIG[] = "autocal";
- static constexpr char LRA_PERIOD_CONFIG[] = "lra_period";
-
- static constexpr uint32_t WAVEFORM_CLICK_EFFECT_MS = 6;
- static constexpr uint32_t WAVEFORM_TICK_EFFECT_MS = 2;
- static constexpr uint32_t WAVEFORM_DOUBLE_CLICK_EFFECT_MS = 135;
- static constexpr uint32_t WAVEFORM_HEAVY_CLICK_EFFECT_MS = 8;
-
- public:
- HwCal();
- bool getAutocal(std::string *value) override { return get(AUTOCAL_CONFIG, value); }
- bool getLraPeriod(uint32_t *value) override { return get(LRA_PERIOD_CONFIG, value); }
- bool getClickDuration(uint32_t *value) override {
- *value = property_get_int32((mPropertyPrefix + "click.duration").c_str(),
- WAVEFORM_CLICK_EFFECT_MS);
- return true;
- }
- bool getTickDuration(uint32_t *value) override {
- *value = property_get_int32((mPropertyPrefix + "tick.duration").c_str(),
- WAVEFORM_TICK_EFFECT_MS);
- return true;
- }
- bool getDoubleClickDuration(uint32_t *value) override {
- *value = WAVEFORM_DOUBLE_CLICK_EFFECT_MS;
- return true;
- }
- bool getHeavyClickDuration(uint32_t *value) override {
- *value = property_get_int32((mPropertyPrefix + "heavyclick.duration").c_str(),
- WAVEFORM_HEAVY_CLICK_EFFECT_MS);
- return true;
- }
- void debug(int fd) override;
-
- private:
- template <typename T>
- bool get(const char *key, T *value);
-
- private:
- std::string mPropertyPrefix;
- std::map<std::string, std::string> mCalData;
-};
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
-
-#endif // ANDROID_HARDWARE_VIBRATOR_HARDWARE_H
diff --git a/vibrator/OWNERS b/vibrator/OWNERS
deleted file mode 100644
index 928c9ff..0000000
--- a/vibrator/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
-chasewu@google.com
-eliptus@google.com
-michaelwr@google.com
diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp
deleted file mode 100644
index e86c4f4..0000000
--- a/vibrator/Vibrator.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * 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.
- */
-
-#define LOG_TAG "VibratorService"
-
-#include "Vibrator.h"
-
-#include <cutils/properties.h>
-#include <hardware/hardware.h>
-#include <hardware/vibrator.h>
-#include <log/log.h>
-
-#include <cinttypes>
-#include <cmath>
-#include <fstream>
-#include <iostream>
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-static constexpr int8_t MAX_RTP_INPUT = 127;
-static constexpr int8_t MIN_RTP_INPUT = 0;
-
-static constexpr char RTP_MODE[] = "rtp";
-static constexpr char WAVEFORM_MODE[] = "waveform";
-
-// Use effect #1 in the waveform library for CLICK effect
-static constexpr char WAVEFORM_CLICK_EFFECT_SEQ[] = "1 0";
-
-// Use effect #2 in the waveform library for TICK effect
-static constexpr char WAVEFORM_TICK_EFFECT_SEQ[] = "2 0";
-
-// Use effect #3 in the waveform library for DOUBLE_CLICK effect
-static constexpr char WAVEFORM_DOUBLE_CLICK_EFFECT_SEQ[] = "3 0";
-
-// Use effect #4 in the waveform library for HEAVY_CLICK effect
-static constexpr char WAVEFORM_HEAVY_CLICK_EFFECT_SEQ[] = "4 0";
-
-// Timeout threshold for selecting open or closed loop mode
-static constexpr int8_t LOOP_MODE_THRESHOLD_MS = 20;
-
-using Status = ::android::hardware::vibrator::V1_0::Status;
-using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength;
-
-Vibrator::Vibrator(std::unique_ptr<HwApi> hwapi, std::unique_ptr<HwCal> hwcal)
- : mHwApi(std::move(hwapi)), mHwCal(std::move(hwcal)) {
- std::string autocal;
- uint32_t lraPeriod;
-
- if (!mHwApi->setState(true)) {
- ALOGE("Failed to set state (%d): %s", errno, strerror(errno));
- }
-
- if (mHwCal->getAutocal(&autocal)) {
- mHwApi->setAutocal(autocal);
- }
- if (mHwCal->getLraPeriod(&lraPeriod)) {
- mHwApi->setOlLraPeriod(lraPeriod);
- }
-
- mHwCal->getClickDuration(&mClickDuration);
- mHwCal->getTickDuration(&mTickDuration);
- mHwCal->getDoubleClickDuration(&mDoubleClickDuration);
- mHwCal->getHeavyClickDuration(&mHeavyClickDuration);
-
- // This enables effect #1 from the waveform library to be triggered by SLPI
- // while the AP is in suspend mode
- if (!mHwApi->setLpTriggerEffect(1)) {
- ALOGW("Failed to set LP trigger mode (%d): %s", errno, strerror(errno));
- }
-}
-
-Return<Status> Vibrator::on(uint32_t timeoutMs, bool forceOpenLoop, bool isWaveform) {
- uint32_t loopMode = 1;
-
- // Open-loop mode is used for short click for over-drive
- // Close-loop mode is used for long notification for stability
- if (!forceOpenLoop && timeoutMs > LOOP_MODE_THRESHOLD_MS) {
- loopMode = 0;
- }
-
- mHwApi->setCtrlLoop(loopMode);
- if (!mHwApi->setDuration(timeoutMs)) {
- ALOGE("Failed to set duration (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
-
- if (isWaveform) {
- mHwApi->setMode(WAVEFORM_MODE);
- } else {
- mHwApi->setMode(RTP_MODE);
- }
-
- if (!mHwApi->setActivate(1)) {
- ALOGE("Failed to activate (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
-
- return Status::OK;
-}
-
-// Methods from ::android::hardware::vibrator::V1_2::IVibrator follow.
-Return<Status> Vibrator::on(uint32_t timeoutMs) {
- return on(timeoutMs, false /* forceOpenLoop */, false /* isWaveform */);
-}
-
-Return<Status> Vibrator::off() {
- if (!mHwApi->setActivate(0)) {
- ALOGE("Failed to turn vibrator off (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
- return Status::OK;
-}
-
-Return<bool> Vibrator::supportsAmplitudeControl() {
- return (mHwApi->hasRtpInput() ? true : false);
-}
-
-Return<Status> Vibrator::setAmplitude(uint8_t amplitude) {
- if (amplitude == 0) {
- return Status::BAD_VALUE;
- }
-
- int32_t rtp_input =
- std::round((amplitude - 1) / 254.0 * (MAX_RTP_INPUT - MIN_RTP_INPUT) + MIN_RTP_INPUT);
-
- if (!mHwApi->setRtpInput(rtp_input)) {
- ALOGE("Failed to set amplitude (%d): %s", errno, strerror(errno));
- return Status::UNKNOWN_ERROR;
- }
-
- return Status::OK;
-}
-
-// Methods from ::android.hidl.base::V1_0::IBase follow.
-
-Return<void> Vibrator::debug(const hidl_handle &handle,
- const hidl_vec<hidl_string> & /* options */) {
- if (handle == nullptr || handle->numFds < 1 || handle->data[0] < 0) {
- ALOGE("Called debug() with invalid fd.");
- return Void();
- }
-
- int fd = handle->data[0];
-
- dprintf(fd, "HIDL:\n");
-
- dprintf(fd, " Click Duration: %" PRIu32 "\n", mClickDuration);
- dprintf(fd, " Tick Duration: %" PRIu32 "\n", mTickDuration);
- dprintf(fd, " Double Click Duration: %" PRIu32 "\n", mDoubleClickDuration);
- dprintf(fd, " Heavy Click Duration: %" PRIu32 "\n", mHeavyClickDuration);
-
- dprintf(fd, "\n");
-
- mHwApi->debug(fd);
-
- dprintf(fd, "\n");
-
- mHwCal->debug(fd);
-
- fsync(fd);
- return Void();
-}
-
-static uint8_t convertEffectStrength(EffectStrength strength) {
- uint8_t scale;
-
- switch (strength) {
- case EffectStrength::LIGHT:
- scale = 2; // 50%
- break;
- case EffectStrength::MEDIUM:
- case EffectStrength::STRONG:
- scale = 0; // 100%
- break;
- }
-
- return scale;
-}
-
-Return<void> Vibrator::perform(V1_0::Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
- return performWrapper(effect, strength, _hidl_cb);
-}
-
-Return<void> Vibrator::perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
- perform_cb _hidl_cb) {
- return performWrapper(effect, strength, _hidl_cb);
-}
-
-Return<void> Vibrator::perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
- return performWrapper(effect, strength, _hidl_cb);
-}
-
-template <typename T>
-Return<void> Vibrator::performWrapper(T effect, EffectStrength strength, perform_cb _hidl_cb) {
- auto validEffectRange = hidl_enum_range<T>();
- if (effect < *validEffectRange.begin() || effect > *std::prev(validEffectRange.end())) {
- _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
- return Void();
- }
- auto validStrengthRange = hidl_enum_range<EffectStrength>();
- if (strength < *validStrengthRange.begin() || strength > *std::prev(validStrengthRange.end())) {
- _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
- return Void();
- }
- return performEffect(static_cast<Effect>(effect), strength, _hidl_cb);
-}
-
-Return<void> Vibrator::performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
- Status status = Status::OK;
- uint32_t timeMS;
-
- switch (effect) {
- case Effect::CLICK:
- mHwApi->setSequencer(WAVEFORM_CLICK_EFFECT_SEQ);
- timeMS = mClickDuration;
- break;
- case Effect::DOUBLE_CLICK:
- mHwApi->setSequencer(WAVEFORM_DOUBLE_CLICK_EFFECT_SEQ);
- timeMS = mDoubleClickDuration;
- break;
- case Effect::TICK:
- mHwApi->setSequencer(WAVEFORM_TICK_EFFECT_SEQ);
- timeMS = mTickDuration;
- break;
- case Effect::HEAVY_CLICK:
- mHwApi->setSequencer(WAVEFORM_HEAVY_CLICK_EFFECT_SEQ);
- timeMS = mHeavyClickDuration;
- break;
- default:
- _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
- return Void();
- }
- mHwApi->setScale(convertEffectStrength(strength));
- on(timeMS, true /* forceOpenLoop */, true /* isWaveform */);
- _hidl_cb(status, timeMS);
- return Void();
-}
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h
deleted file mode 100644
index 9900a2e..0000000
--- a/vibrator/Vibrator.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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.
- */
-#ifndef ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H
-#define ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H
-
-#include <android/hardware/vibrator/1.2/IVibrator.h>
-#include <hidl/Status.h>
-
-#include <fstream>
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-class Vibrator : public IVibrator {
- public:
- // APIs for interfacing with the kernel driver.
- class HwApi {
- public:
- virtual ~HwApi() = default;
- // Stores the COMP, BEMF, and GAIN calibration values to use.
- // <COMP> <BEMF> <GAIN>
- virtual bool setAutocal(std::string value) = 0;
- // Stores the open-loop LRA frequency to be used.
- virtual bool setOlLraPeriod(uint32_t value) = 0;
- // Activates/deactivates the vibrator for durations specified by
- // setDuration().
- virtual bool setActivate(bool value) = 0;
- // Specifies the vibration duration in milliseconds.
- virtual bool setDuration(uint32_t value) = 0;
- // Specifies the active state of the vibrator
- // (true = enabled, false = disabled).
- virtual bool setState(bool value) = 0;
- // Reports whether setRtpInput() is supported.
- virtual bool hasRtpInput() = 0;
- // Specifies the playback amplitude of the haptic waveforms in RTP mode.
- // Negative numbers indicates braking.
- virtual bool setRtpInput(int8_t value) = 0;
- // Specifies the mode of operation.
- // rtp - RTP Mode
- // waveform - Waveform Sequencer Mode
- // diag - Diagnostics Routine
- // autocal - Automatic Level Calibration Routine
- virtual bool setMode(std::string value) = 0;
- // Specifies a waveform sequence in index-count pairs.
- // <index-1> <count-1> [<index-2> <cound-2> ...]
- virtual bool setSequencer(std::string value) = 0;
- // Specifies the scaling of effects in Waveform mode.
- // 0 - 100%
- // 1 - 75%
- // 2 - 50%
- // 3 - 25%
- virtual bool setScale(uint8_t value) = 0;
- // Selects either closed loop or open loop mode.
- // (true = open, false = closed).
- virtual bool setCtrlLoop(bool value) = 0;
- // Specifies waveform index to be played in low-power trigger mode.
- // 0 - Disabled
- // 1+ - Waveform Index
- virtual bool setLpTriggerEffect(uint32_t value) = 0;
- // Emit diagnostic information to the given file.
- virtual void debug(int fd) = 0;
- };
-
- // APIs for obtaining calibration/configuration data from persistent memory.
- class HwCal {
- public:
- virtual ~HwCal() = default;
- // Obtains the COMP, BEMF, and GAIN calibration values to use.
- virtual bool getAutocal(std::string *value) = 0;
- // Obtains the open-loop LRA frequency to be used.
- virtual bool getLraPeriod(uint32_t *value) = 0;
- // Obtains the duration for the click effect
- virtual bool getClickDuration(uint32_t *value) = 0;
- // Obtains the duration for the tick effect
- virtual bool getTickDuration(uint32_t *value) = 0;
- // Obtains the duration for the double-click effect
- virtual bool getDoubleClickDuration(uint32_t *value) = 0;
- // Obtains the duration for the heavy-click effect
- virtual bool getHeavyClickDuration(uint32_t *value) = 0;
- // Emit diagnostic information to the given file.
- virtual void debug(int fd) = 0;
- };
-
- public:
- Vibrator(std::unique_ptr<HwApi> hwapi, std::unique_ptr<HwCal> hwcal);
-
- // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
- using Status = ::android::hardware::vibrator::V1_0::Status;
- Return<Status> on(uint32_t timeoutMs) override;
- Return<Status> off() override;
- Return<bool> supportsAmplitudeControl() override;
- Return<Status> setAmplitude(uint8_t amplitude) override;
-
- using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength;
- Return<void> perform(V1_0::Effect effect, EffectStrength strength,
- perform_cb _hidl_cb) override;
- Return<void> perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
- perform_cb _hidl_cb) override;
- Return<void> perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
-
- // Methods from ::android.hidl.base::V1_0::IBase follow.
- Return<void> debug(const hidl_handle &handle, const hidl_vec<hidl_string> &options) override;
-
- private:
- Return<Status> on(uint32_t timeoutMs, bool forceOpenLoop, bool isWaveform);
- template <typename T>
- Return<void> performWrapper(T effect, EffectStrength strength, perform_cb _hidl_cb);
- Return<void> performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb);
- std::unique_ptr<HwApi> mHwApi;
- std::unique_ptr<HwCal> mHwCal;
- uint32_t mClickDuration;
- uint32_t mTickDuration;
- uint32_t mDoubleClickDuration;
- uint32_t mHeavyClickDuration;
-};
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
-
-#endif // ANDROID_HARDWARE_VIBRATOR_V1_2_VIBRATOR_H
diff --git a/vibrator/android.hardware.vibrator@1.2-service.drv2624.rc b/vibrator/android.hardware.vibrator@1.2-service.drv2624.rc
deleted file mode 100644
index 791d321..0000000
--- a/vibrator/android.hardware.vibrator@1.2-service.drv2624.rc
+++ /dev/null
@@ -1,26 +0,0 @@
-service vendor.vibrator-1-2 /vendor/bin/hw/android.hardware.vibrator@1.2-service.drv2624
- class hal
- user system
- group system
-
- setenv PROPERTY_PREFIX ro.vibrator.hal.
- setenv CALIBRATION_FILEPATH /persist/haptics/drv2624.cal
-
- setenv AUTOCAL_FILEPATH /sys/class/leds/vibrator/device/autocal
- setenv OL_LRA_PERIOD_FILEPATH /sys/class/leds/vibrator/device/ol_lra_period
- setenv ACTIVATE_PATH /sys/class/leds/vibrator/activate
- setenv DURATION_PATH /sys/class/leds/vibrator/duration
- setenv STATE_PATH /sys/class/leds/vibrator/state
- setenv RTP_INPUT_PATH /sys/class/leds/vibrator/device/rtp_input
- setenv MODE_PATH /sys/class/leds/vibrator/device/mode
- setenv SEQUENCER_PATH /sys/class/leds/vibrator/device/set_sequencer
- setenv SCALE_PATH /sys/class/leds/vibrator/device/scale
- setenv CTRL_LOOP_PATH /sys/class/leds/vibrator/device/ctrl_loop
- setenv LP_TRIGGER_PATH /sys/class/leds/vibrator/device/lp_trigger_effect
-
- setenv HWAPI_DEBUG_PATHS "
- /sys/class/leds/vibrator/device/autocal
- /sys/class/leds/vibrator/device/lp_trigger_effect
- /sys/class/leds/vibrator/device/ol_lra_period
- /sys/class/leds/vibrator/state
- "
diff --git a/vibrator/android.hardware.vibrator@1.2-service.drv2624.xml b/vibrator/android.hardware.vibrator@1.2-service.drv2624.xml
deleted file mode 100644
index cc5825d..0000000
--- a/vibrator/android.hardware.vibrator@1.2-service.drv2624.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<manifest version="1.0" type="device">
- <hal format="hidl">
- <name>android.hardware.vibrator</name>
- <transport>hwbinder</transport>
- <version>1.2</version>
- <interface>
- <name>IVibrator</name>
- <instance>default</instance>
- </interface>
- </hal>
-</manifest>
diff --git a/vibrator/service.cpp b/vibrator/service.cpp
deleted file mode 100644
index f5f736a..0000000
--- a/vibrator/service.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- */
-#define LOG_TAG "android.hardware.vibrator@1.2-service.drv2624"
-
-#include <android/hardware/vibrator/1.2/IVibrator.h>
-#include <hidl/HidlSupport.h>
-#include <hidl/HidlTransportSupport.h>
-#include <utils/Errors.h>
-#include <utils/StrongPointer.h>
-
-#include "Hardware.h"
-#include "Vibrator.h"
-
-using android::OK;
-using android::sp;
-using android::status_t;
-using android::UNKNOWN_ERROR;
-using android::hardware::configureRpcThreadpool;
-using android::hardware::joinRpcThreadpool;
-using android::hardware::vibrator::V1_2::implementation::HwApi;
-using android::hardware::vibrator::V1_2::implementation::HwCal;
-using android::hardware::vibrator::V1_2::implementation::Vibrator;
-
-status_t registerVibratorService() {
- auto hwapi = HwApi::Create();
-
- if (!hwapi) {
- return UNKNOWN_ERROR;
- }
-
- sp<Vibrator> vibrator = new Vibrator(std::move(hwapi), std::make_unique<HwCal>());
-
- return vibrator->registerAsService();
-}
-
-int main() {
- configureRpcThreadpool(1, true);
- status_t status = registerVibratorService();
-
- if (status != OK) {
- return status;
- }
-
- joinRpcThreadpool();
-}
diff --git a/vibrator/tests/mocks.h b/vibrator/tests/mocks.h
deleted file mode 100644
index b7a15ff..0000000
--- a/vibrator/tests/mocks.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.
- */
-#ifndef ANDROID_HARDWARE_VIBRATOR_TEST_MOCKS_H
-#define ANDROID_HARDWARE_VIBRATOR_TEST_MOCKS_H
-
-#include "Vibrator.h"
-
-class MockApi : public ::android::hardware::vibrator::V1_2::implementation::Vibrator::HwApi {
- public:
- MOCK_METHOD0(destructor, void());
- MOCK_METHOD1(setAutocal, bool(std::string value));
- MOCK_METHOD1(setOlLraPeriod, bool(uint32_t value));
- MOCK_METHOD1(setActivate, bool(bool value));
- MOCK_METHOD1(setDuration, bool(uint32_t value));
- MOCK_METHOD1(setState, bool(bool value));
- MOCK_METHOD0(hasRtpInput, bool());
- MOCK_METHOD1(setRtpInput, bool(int8_t value));
- MOCK_METHOD1(setMode, bool(std::string value));
- MOCK_METHOD1(setSequencer, bool(std::string value));
- MOCK_METHOD1(setScale, bool(uint8_t value));
- MOCK_METHOD1(setCtrlLoop, bool(bool value));
- MOCK_METHOD1(setLpTriggerEffect, bool(uint32_t value));
- MOCK_METHOD1(debug, void(int fd));
-
- ~MockApi() override { destructor(); };
-};
-
-class MockCal : public ::android::hardware::vibrator::V1_2::implementation::Vibrator::HwCal {
- public:
- MOCK_METHOD0(destructor, void());
- MOCK_METHOD1(getAutocal, bool(std::string &value)); // NOLINT
- MOCK_METHOD1(getLraPeriod, bool(uint32_t *value));
- MOCK_METHOD1(getClickDuration, bool(uint32_t *value));
- MOCK_METHOD1(getTickDuration, bool(uint32_t *value));
- MOCK_METHOD1(getDoubleClickDuration, bool(uint32_t *value));
- MOCK_METHOD1(getHeavyClickDuration, bool(uint32_t *value));
- MOCK_METHOD1(debug, void(int fd));
-
- ~MockCal() override { destructor(); };
- // b/132668253: Workaround gMock Compilation Issue
- bool getAutocal(std::string *value) { return getAutocal(*value); }
-};
-
-#endif // ANDROID_HARDWARE_VIBRATOR_TEST_MOCKS_H
diff --git a/vibrator/tests/test-hwapi.cpp b/vibrator/tests/test-hwapi.cpp
deleted file mode 100644
index e919f8f..0000000
--- a/vibrator/tests/test-hwapi.cpp
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * 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.
- */
-#define LOG_TAG "PtsVibratorHalDrv2624TestSuite"
-
-#include <android-base/file.h>
-#include <gtest/gtest.h>
-
-#include <cstdlib>
-#include <fstream>
-
-#include "Hardware.h"
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-using ::testing::Test;
-using ::testing::TestParamInfo;
-using ::testing::ValuesIn;
-using ::testing::WithParamInterface;
-
-class HwApiTest : public Test {
- protected:
- static constexpr const char *FILE_NAMES[]{
- "AUTOCAL_FILEPATH", "OL_LRA_PERIOD_FILEPATH", "ACTIVATE_PATH", "DURATION_PATH",
- "STATE_PATH", "RTP_INPUT_PATH", "MODE_PATH", "SEQUENCER_PATH",
- "SCALE_PATH", "CTRL_LOOP_PATH", "LP_TRIGGER_PATH",
- };
-
- static constexpr const char *REQUIRED[]{
- "ACTIVATE_PATH",
- "DURATION_PATH",
- "STATE_PATH",
- };
-
- public:
- void SetUp() override {
- for (auto n : FILE_NAMES) {
- auto name = std::string(n);
- auto path = std::string(mFilesDir.path) + "/" + name;
- std::ofstream touch{path};
- setenv(name.c_str(), path.c_str(), true);
- mFileMap[name] = path;
- }
- mHwApi = HwApi::Create();
-
- for (auto n : REQUIRED) {
- auto name = std::string(n);
- auto path = std::string(mEmptyDir.path) + "/" + name;
- std::ofstream touch{path};
- }
- for (auto n : FILE_NAMES) {
- auto name = std::string(n);
- auto path = std::string(mEmptyDir.path) + "/" + name;
- setenv(name.c_str(), path.c_str(), true);
- }
- mNoApi = HwApi::Create();
- }
-
- void TearDown() override { verifyContents(); }
-
- protected:
- // Set expected file content for a test.
- template <typename T>
- void expectContent(const std::string &name, const T &value) {
- mExpectedContent[name] << value << std::endl;
- }
-
- // Set actual file content for an input test.
- template <typename T>
- void updateContent(const std::string &name, const T &value) {
- std::ofstream(mFileMap[name]) << value << std::endl;
- }
-
- template <typename T>
- void expectAndUpdateContent(const std::string &name, const T &value) {
- expectContent(name, value);
- updateContent(name, value);
- }
-
- // Compare all file contents against expected contents.
- void verifyContents() {
- for (auto &a : mFileMap) {
- std::ifstream file{a.second};
- std::string expect = mExpectedContent[a.first].str();
- std::string actual = std::string(std::istreambuf_iterator<char>(file),
- std::istreambuf_iterator<char>());
- EXPECT_EQ(expect, actual) << a.first;
- }
- }
-
- // TODO(eliptus): Determine how to induce errors in required files
- static bool isRequired(const std::string &name) {
- for (auto n : REQUIRED) {
- if (std::string(n) == name) {
- return true;
- }
- }
- return false;
- }
-
- protected:
- std::unique_ptr<Vibrator::HwApi> mHwApi;
- std::unique_ptr<Vibrator::HwApi> mNoApi;
- std::map<std::string, std::string> mFileMap;
- TemporaryDir mFilesDir;
- TemporaryDir mEmptyDir;
- std::map<std::string, std::stringstream> mExpectedContent;
-};
-
-class CreateTest : public HwApiTest, public testing::WithParamInterface<const char *> {
- public:
- void SetUp() override{};
- void TearDown() override{};
-
- static auto PrintParam(const testing::TestParamInfo<CreateTest::ParamType> &info) {
- return info.param;
- }
- static auto &AllParams() { return FILE_NAMES; }
-};
-
-TEST_P(CreateTest, env_missing) {
- auto skip = std::string(GetParam());
- TemporaryDir dir;
- std::unique_ptr<HwApi> hwapi;
-
- for (auto n : FILE_NAMES) {
- auto name = std::string(n);
- if (name == skip) {
- unsetenv(name.c_str());
- continue;
- }
- auto path = std::string(dir.path) + "/" + name;
- std::ofstream touch{path};
- setenv(name.c_str(), path.c_str(), true);
- }
-
- hwapi = HwApi::Create();
- if (isRequired(skip)) {
- EXPECT_EQ(nullptr, hwapi);
- } else {
- EXPECT_NE(nullptr, hwapi);
- }
-}
-
-TEST_P(CreateTest, file_missing) {
- auto skip = std::string(GetParam());
- TemporaryDir dir;
- std::unique_ptr<HwApi> hwapi;
-
- for (auto n : FILE_NAMES) {
- auto name = std::string(n);
- auto path = std::string(dir.path) + "/" + name;
- setenv(name.c_str(), path.c_str(), true);
- if (name == skip) {
- continue;
- }
- std::ofstream touch{path};
- }
-
- hwapi = HwApi::Create();
- if (isRequired(skip)) {
- EXPECT_EQ(nullptr, hwapi);
- } else {
- EXPECT_NE(nullptr, hwapi);
- }
-}
-
-INSTANTIATE_TEST_CASE_P(HwApiTests, CreateTest, ValuesIn(CreateTest::AllParams()),
- CreateTest::PrintParam);
-
-template <typename T>
-class HwApiTypedTest
- : public HwApiTest,
- public testing::WithParamInterface<std::tuple<std::string, std::function<T>>> {
- public:
- static auto PrintParam(const testing::TestParamInfo<typename HwApiTypedTest::ParamType> &info) {
- return std::get<0>(info.param);
- }
- static auto MakeParam(std::string name, std::function<T> func) {
- return std::make_tuple(name, func);
- }
-};
-
-using HasTest = HwApiTypedTest<bool(Vibrator::HwApi &)>;
-
-TEST_P(HasTest, success_returnsTrue) {
- auto param = GetParam();
- auto func = std::get<1>(param);
-
- EXPECT_TRUE(func(*mHwApi));
-}
-
-TEST_P(HasTest, success_returnsFalse) {
- auto param = GetParam();
- auto func = std::get<1>(param);
-
- EXPECT_FALSE(func(*mNoApi));
-}
-
-INSTANTIATE_TEST_CASE_P(HwApiTests, HasTest,
- ValuesIn({
- HasTest::MakeParam("RTP_INPUT_PATH", &Vibrator::HwApi::hasRtpInput),
- }),
- HasTest::PrintParam);
-
-using SetBoolTest = HwApiTypedTest<bool(Vibrator::HwApi &, bool)>;
-
-TEST_P(SetBoolTest, success_returnsTrue) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
-
- expectContent(name, "1");
-
- EXPECT_TRUE(func(*mHwApi, true));
-}
-
-TEST_P(SetBoolTest, success_returnsFalse) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
-
- expectContent(name, "0");
-
- EXPECT_TRUE(func(*mHwApi, false));
-}
-
-TEST_P(SetBoolTest, failure) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
-
- if (isRequired(name)) {
- GTEST_SKIP();
- }
-
- EXPECT_FALSE(func(*mNoApi, true));
- EXPECT_FALSE(func(*mNoApi, false));
-}
-
-INSTANTIATE_TEST_CASE_P(
- HwApiTests, SetBoolTest,
- ValuesIn({
- SetBoolTest::MakeParam("ACTIVATE_PATH", &Vibrator::HwApi::setActivate),
- SetBoolTest::MakeParam("STATE_PATH", &Vibrator::HwApi::setState),
- SetBoolTest::MakeParam("CTRL_LOOP_PATH", &Vibrator::HwApi::setCtrlLoop),
- }),
- SetBoolTest::PrintParam);
-
-using SetInt8Test = HwApiTypedTest<bool(Vibrator::HwApi &, int8_t)>;
-
-TEST_P(SetInt8Test, success) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- int8_t value = std::rand();
-
- expectContent(name, +value);
-
- EXPECT_TRUE(func(*mHwApi, value));
-}
-
-TEST_P(SetInt8Test, failure) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- int8_t value = std::rand();
-
- if (isRequired(name)) {
- GTEST_SKIP();
- }
-
- EXPECT_FALSE(func(*mNoApi, value));
-}
-
-INSTANTIATE_TEST_CASE_P(HwApiTests, SetInt8Test,
- ValuesIn({
- SetInt8Test::MakeParam("RTP_INPUT_PATH",
- &Vibrator::HwApi::setRtpInput),
- }),
- SetInt8Test::PrintParam);
-
-using SetUint8Test = HwApiTypedTest<bool(Vibrator::HwApi &, uint8_t)>;
-
-TEST_P(SetUint8Test, success) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- uint8_t value = std::rand();
-
- expectContent(name, +value);
-
- EXPECT_TRUE(func(*mHwApi, value));
-}
-
-TEST_P(SetUint8Test, failure) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- uint8_t value = std::rand();
-
- if (isRequired(name)) {
- GTEST_SKIP();
- }
-
- EXPECT_FALSE(func(*mNoApi, value));
-}
-
-INSTANTIATE_TEST_CASE_P(HwApiTests, SetUint8Test,
- ValuesIn({
- SetUint8Test::MakeParam("SCALE_PATH", &Vibrator::HwApi::setScale),
- }),
- SetUint8Test::PrintParam);
-
-using SetUint32Test = HwApiTypedTest<bool(Vibrator::HwApi &, uint32_t)>;
-
-TEST_P(SetUint32Test, success) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- uint32_t value = std::rand();
-
- expectContent(name, value);
-
- EXPECT_TRUE(func(*mHwApi, value));
-}
-
-TEST_P(SetUint32Test, failure) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- uint32_t value = std::rand();
-
- if (isRequired(name)) {
- GTEST_SKIP();
- }
-
- EXPECT_FALSE(func(*mNoApi, value));
-}
-
-INSTANTIATE_TEST_CASE_P(
- HwApiTests, SetUint32Test,
- ValuesIn({
- SetUint32Test::MakeParam("OL_LRA_PERIOD_FILEPATH",
- &Vibrator::HwApi::setOlLraPeriod),
- SetUint32Test::MakeParam("DURATION_PATH", &Vibrator::HwApi::setDuration),
- SetUint32Test::MakeParam("LP_TRIGGER_PATH", &Vibrator::HwApi::setLpTriggerEffect),
- }),
- SetUint32Test::PrintParam);
-
-using SetStringTest = HwApiTypedTest<bool(Vibrator::HwApi &, std::string)>;
-
-TEST_P(SetStringTest, success) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- std::string value = TemporaryFile().path;
-
- expectContent(name, value);
-
- EXPECT_TRUE(func(*mHwApi, value));
-}
-
-TEST_P(SetStringTest, failure) {
- auto param = GetParam();
- auto name = std::get<0>(param);
- auto func = std::get<1>(param);
- std::string value = TemporaryFile().path;
-
- if (isRequired(name)) {
- GTEST_SKIP();
- }
-
- EXPECT_FALSE(func(*mNoApi, value));
-}
-
-INSTANTIATE_TEST_CASE_P(
- HwApiTests, SetStringTest,
- ValuesIn({
- SetStringTest::MakeParam("AUTOCAL_FILEPATH", &Vibrator::HwApi::setAutocal),
- SetStringTest::MakeParam("MODE_PATH", &Vibrator::HwApi::setMode),
- SetStringTest::MakeParam("SEQUENCER_PATH", &Vibrator::HwApi::setSequencer),
- }),
- SetStringTest::PrintParam);
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
diff --git a/vibrator/tests/test-hwcal.cpp b/vibrator/tests/test-hwcal.cpp
deleted file mode 100644
index 1b8c219..0000000
--- a/vibrator/tests/test-hwcal.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * 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.
- */
-#define LOG_TAG "PtsVibratorHalDrv2624TestSuite"
-
-#include <android-base/file.h>
-#include <android-base/properties.h>
-#include <gtest/gtest.h>
-
-#include <fstream>
-
-#include "Hardware.h"
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-using ::android::base::SetProperty;
-using ::android::base::WaitForProperty;
-
-using ::testing::Test;
-
-class HwCalTest : public Test {
- protected:
- static constexpr char PROPERTY_PREFIX[] = "test.vibrator.hal.";
-
- static constexpr uint32_t DEFAULT_CLICK_DURATION_MS = 6;
- static constexpr uint32_t DEFAULT_TICK_DURATION_MS = 2;
- static constexpr uint32_t DEFAULT_DOUBLE_CLICK_DURATION_MS = 135;
- static constexpr uint32_t DEFAULT_HEAVY_CLICK_DURATION_MS = 8;
-
- public:
- void SetUp() override {
- setenv("PROPERTY_PREFIX", PROPERTY_PREFIX, true);
- setenv("CALIBRATION_FILEPATH", mCalFile.path, true);
- }
-
- private:
- template <typename T>
- static void pack(std::ostream &stream, const T &value, std::string lpad, std::string rpad) {
- stream << lpad << value << rpad;
- }
-
- protected:
- void createHwCal() { mHwCal = std::make_unique<HwCal>(); }
-
- template <typename T>
- void write(const std::string key, const T &value, std::string lpad = " ",
- std::string rpad = "") {
- std::ofstream calfile{mCalFile.path, std::ios_base::app};
- calfile << key << ":";
- pack(calfile, value, lpad, rpad);
- calfile << std::endl;
- }
-
- void unlink() { ::unlink(mCalFile.path); }
-
- protected:
- std::unique_ptr<Vibrator::HwCal> mHwCal;
- TemporaryFile mCalFile;
-};
-
-TEST_F(HwCalTest, click_present) {
- std::string prefix{PROPERTY_PREFIX};
- uint32_t expect = std::rand();
- uint32_t actual = ~expect;
-
- EXPECT_TRUE(SetProperty(prefix + "click.duration", std::to_string(expect)));
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getClickDuration(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, click_missing) {
- std::string prefix{PROPERTY_PREFIX};
- uint32_t expect = DEFAULT_CLICK_DURATION_MS;
- uint32_t actual = ~expect;
-
- EXPECT_TRUE(SetProperty(prefix + "click.duration", std::string()));
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getClickDuration(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, tick_present) {
- std::string prefix{PROPERTY_PREFIX};
- uint32_t expect = std::rand();
- uint32_t actual = ~expect;
-
- EXPECT_TRUE(SetProperty(prefix + "tick.duration", std::to_string(expect)));
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getTickDuration(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, tick_missing) {
- std::string prefix{PROPERTY_PREFIX};
- uint32_t expect = DEFAULT_TICK_DURATION_MS;
- uint32_t actual = ~expect;
-
- EXPECT_TRUE(SetProperty(prefix + "tick.duration", std::string()));
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getTickDuration(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, doubleclick) {
- std::string prefix{PROPERTY_PREFIX};
- uint32_t expect = DEFAULT_DOUBLE_CLICK_DURATION_MS;
- uint32_t actual = ~expect;
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getDoubleClickDuration(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, heavyclick_present) {
- std::string prefix{PROPERTY_PREFIX};
- uint32_t expect = std::rand();
- uint32_t actual = ~expect;
-
- EXPECT_TRUE(SetProperty(prefix + "heavyclick.duration", std::to_string(expect)));
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getHeavyClickDuration(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, heavyclick_missing) {
- std::string prefix{PROPERTY_PREFIX};
- uint32_t expect = DEFAULT_HEAVY_CLICK_DURATION_MS;
- uint32_t actual = ~expect;
-
- EXPECT_TRUE(SetProperty(prefix + "heavyclick.duration", std::string()));
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getHeavyClickDuration(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, autocal_present) {
- std::string expect = std::to_string(std::rand()) + " " + std::to_string(std::rand()) + " " +
- std::to_string(std::rand());
- std::string actual = "";
-
- write("autocal", expect);
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getAutocal(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, autocal_missing) {
- std::string actual;
-
- createHwCal();
-
- EXPECT_FALSE(mHwCal->getAutocal(&actual));
-}
-
-TEST_F(HwCalTest, lra_period_present) {
- uint32_t expect = std::rand();
- uint32_t actual = ~expect;
-
- write("lra_period", expect);
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getLraPeriod(&actual));
- EXPECT_EQ(expect, actual);
-}
-
-TEST_F(HwCalTest, lra_period_missing) {
- uint32_t actual;
-
- createHwCal();
-
- EXPECT_FALSE(mHwCal->getLraPeriod(&actual));
-}
-
-TEST_F(HwCalTest, multiple) {
- std::string autocalExpect = std::to_string(std::rand()) + " " + std::to_string(std::rand()) +
- " " + std::to_string(std::rand());
- std::string autocalActual = "";
- uint32_t lraPeriodExpect = std::rand();
- uint32_t lraPeriodActual = ~lraPeriodExpect;
-
- write("autocal", autocalExpect);
- write("lra_period", lraPeriodExpect);
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getAutocal(&autocalActual));
- EXPECT_EQ(autocalExpect, autocalActual);
- EXPECT_TRUE(mHwCal->getLraPeriod(&lraPeriodActual));
- EXPECT_EQ(lraPeriodExpect, lraPeriodActual);
-}
-
-TEST_F(HwCalTest, trimming) {
- std::string autocalExpect = std::to_string(std::rand()) + " " + std::to_string(std::rand()) +
- " " + std::to_string(std::rand());
- std::string autocalActual = "";
- uint32_t lraPeriodExpect = std::rand();
- uint32_t lraPeriodActual = ~lraPeriodExpect;
-
- write("autocal", autocalExpect, " \t", "\t ");
- write("lra_period", lraPeriodExpect, " \t", "\t ");
-
- createHwCal();
-
- EXPECT_TRUE(mHwCal->getAutocal(&autocalActual));
- EXPECT_EQ(autocalExpect, autocalActual);
- EXPECT_TRUE(mHwCal->getLraPeriod(&lraPeriodActual));
- EXPECT_EQ(lraPeriodExpect, lraPeriodActual);
-}
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
diff --git a/vibrator/tests/test-vibrator.cpp b/vibrator/tests/test-vibrator.cpp
deleted file mode 100644
index bc08285..0000000
--- a/vibrator/tests/test-vibrator.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * 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.
- */
-#define LOG_TAG "PtsVibratorHalDrv2624TestSuite"
-
-#include <android-base/logging.h>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-#include "Vibrator.h"
-#include "mocks.h"
-#include "types.h"
-#include "utils.h"
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace V1_2 {
-namespace implementation {
-
-using ::android::hardware::vibrator::V1_0::EffectStrength;
-using ::android::hardware::vibrator::V1_0::Status;
-
-using ::testing::_;
-using ::testing::AnyNumber;
-using ::testing::AnyOf;
-using ::testing::Assign;
-using ::testing::Combine;
-using ::testing::DoAll;
-using ::testing::DoDefault;
-using ::testing::Exactly;
-using ::testing::Mock;
-using ::testing::Return;
-using ::testing::Sequence;
-using ::testing::SetArgPointee;
-using ::testing::SetArgReferee;
-using ::testing::Test;
-using ::testing::TestParamInfo;
-using ::testing::ValuesIn;
-using ::testing::WithParamInterface;
-
-// Constants With Prescribed Values
-
-static const std::map<EffectTuple, EffectSequence> EFFECT_SEQUENCES{
- {{Effect::CLICK, EffectStrength::LIGHT}, {"1 0", 2}},
- {{Effect::CLICK, EffectStrength::MEDIUM}, {"1 0", 0}},
- {{Effect::CLICK, EffectStrength::STRONG}, {"1 0", 0}},
- {{Effect::TICK, EffectStrength::LIGHT}, {"2 0", 2}},
- {{Effect::TICK, EffectStrength::MEDIUM}, {"2 0", 0}},
- {{Effect::TICK, EffectStrength::STRONG}, {"2 0", 0}},
- {{Effect::DOUBLE_CLICK, EffectStrength::LIGHT}, {"3 0", 2}},
- {{Effect::DOUBLE_CLICK, EffectStrength::MEDIUM}, {"3 0", 0}},
- {{Effect::DOUBLE_CLICK, EffectStrength::STRONG}, {"3 0", 0}},
- {{Effect::HEAVY_CLICK, EffectStrength::LIGHT}, {"4 0", 2}},
- {{Effect::HEAVY_CLICK, EffectStrength::MEDIUM}, {"4 0", 0}},
- {{Effect::HEAVY_CLICK, EffectStrength::STRONG}, {"4 0", 0}},
-};
-
-class VibratorTest : public Test, public WithParamInterface<EffectTuple> {
- public:
- void SetUp() override {
- std::unique_ptr<MockApi> mockapi;
- std::unique_ptr<MockCal> mockcal;
-
- mEffectDurations[Effect::CLICK] = std::rand();
- mEffectDurations[Effect::TICK] = std::rand();
- mEffectDurations[Effect::DOUBLE_CLICK] = std::rand();
- mEffectDurations[Effect::HEAVY_CLICK] = std::rand();
-
- createMock(&mockapi, &mockcal);
- createVibrator(std::move(mockapi), std::move(mockcal));
- }
-
- void TearDown() override { deleteVibrator(); }
-
- protected:
- void createMock(std::unique_ptr<MockApi> *mockapi, std::unique_ptr<MockCal> *mockcal) {
- *mockapi = std::make_unique<MockApi>();
- *mockcal = std::make_unique<MockCal>();
-
- mMockApi = mockapi->get();
- mMockCal = mockcal->get();
-
- ON_CALL(*mMockApi, destructor()).WillByDefault(Assign(&mMockApi, nullptr));
-
- ON_CALL(*mMockCal, destructor()).WillByDefault(Assign(&mMockCal, nullptr));
- ON_CALL(*mMockCal, getClickDuration(_))
- .WillByDefault(DoAll(SetArgPointee<0>(mEffectDurations[Effect::CLICK]),
- ::testing::Return(true)));
- ON_CALL(*mMockCal, getTickDuration(_))
- .WillByDefault(DoAll(SetArgPointee<0>(mEffectDurations[Effect::TICK]),
- ::testing::Return(true)));
- ON_CALL(*mMockCal, getDoubleClickDuration(_))
- .WillByDefault(DoAll(SetArgPointee<0>(mEffectDurations[Effect::DOUBLE_CLICK]),
- ::testing::Return(true)));
- ON_CALL(*mMockCal, getHeavyClickDuration(_))
- .WillByDefault(DoAll(SetArgPointee<0>(mEffectDurations[Effect::HEAVY_CLICK]),
- ::testing::Return(true)));
-
- relaxMock(false);
- }
-
- void createVibrator(std::unique_ptr<MockApi> mockapi, std::unique_ptr<MockCal> mockcal,
- bool relaxed = true) {
- if (relaxed) {
- relaxMock(true);
- }
- mVibrator = new Vibrator(std::move(mockapi), std::move(mockcal));
- if (relaxed) {
- relaxMock(false);
- }
- }
-
- void deleteVibrator(bool relaxed = true) {
- if (relaxed) {
- relaxMock(true);
- }
- mVibrator.clear();
- }
-
- private:
- void relaxMock(bool relax) {
- auto times = relax ? AnyNumber() : Exactly(0);
-
- Mock::VerifyAndClearExpectations(mMockApi);
- Mock::VerifyAndClearExpectations(mMockCal);
-
- EXPECT_CALL(*mMockApi, destructor()).Times(times);
- EXPECT_CALL(*mMockApi, setAutocal(_)).Times(times);
- EXPECT_CALL(*mMockApi, setOlLraPeriod(_)).Times(times);
- EXPECT_CALL(*mMockApi, setActivate(_)).Times(times);
- EXPECT_CALL(*mMockApi, setDuration(_)).Times(times);
- EXPECT_CALL(*mMockApi, setState(_)).Times(times);
- EXPECT_CALL(*mMockApi, hasRtpInput()).Times(times);
- EXPECT_CALL(*mMockApi, setRtpInput(_)).Times(times);
- EXPECT_CALL(*mMockApi, setMode(_)).Times(times);
- EXPECT_CALL(*mMockApi, setSequencer(_)).Times(times);
- EXPECT_CALL(*mMockApi, setScale(_)).Times(times);
- EXPECT_CALL(*mMockApi, setCtrlLoop(_)).Times(times);
- EXPECT_CALL(*mMockApi, setLpTriggerEffect(_)).Times(times);
- EXPECT_CALL(*mMockApi, debug(_)).Times(times);
-
- EXPECT_CALL(*mMockCal, destructor()).Times(times);
- EXPECT_CALL(*mMockCal, getAutocal(_)).Times(times);
- EXPECT_CALL(*mMockCal, getLraPeriod(_)).Times(times);
- EXPECT_CALL(*mMockCal, getClickDuration(_)).Times(times);
- EXPECT_CALL(*mMockCal, getTickDuration(_)).Times(times);
- EXPECT_CALL(*mMockCal, getDoubleClickDuration(_)).Times(times);
- EXPECT_CALL(*mMockCal, getHeavyClickDuration(_)).Times(times);
- EXPECT_CALL(*mMockCal, debug(_)).Times(times);
- }
-
- protected:
- MockApi *mMockApi;
- MockCal *mMockCal;
- sp<IVibrator> mVibrator;
-
- std::map<Effect, EffectDuration> mEffectDurations;
-};
-
-TEST_F(VibratorTest, Constructor) {
- std::unique_ptr<MockApi> mockapi;
- std::unique_ptr<MockCal> mockcal;
- std::string autocalVal = std::to_string(std::rand()) + " " + std::to_string(std::rand()) + " " +
- std::to_string(std::rand());
- uint32_t lraPeriodVal = std::rand();
- Sequence autocalSeq, lraPeriodSeq;
-
- EXPECT_CALL(*mMockApi, destructor()).WillOnce(DoDefault());
- EXPECT_CALL(*mMockCal, destructor()).WillOnce(DoDefault());
-
- deleteVibrator(false);
-
- createMock(&mockapi, &mockcal);
-
- EXPECT_CALL(*mMockApi, setState(true)).WillOnce(::testing::Return(true));
-
- EXPECT_CALL(*mMockCal, getAutocal(_))
- .InSequence(autocalSeq)
- .WillOnce(DoAll(SetArgReferee<0>(autocalVal), ::testing::Return(true)));
- EXPECT_CALL(*mMockApi, setAutocal(autocalVal))
- .InSequence(autocalSeq)
- .WillOnce(::testing::Return(true));
-
- EXPECT_CALL(*mMockCal, getLraPeriod(_))
- .InSequence(lraPeriodSeq)
- .WillOnce(DoAll(SetArgPointee<0>(lraPeriodVal), ::testing::Return(true)));
- EXPECT_CALL(*mMockApi, setOlLraPeriod(lraPeriodVal))
- .InSequence(lraPeriodSeq)
- .WillOnce(::testing::Return(true));
-
- EXPECT_CALL(*mMockCal, getClickDuration(_)).WillOnce(DoDefault());
- EXPECT_CALL(*mMockCal, getTickDuration(_)).WillOnce(DoDefault());
- EXPECT_CALL(*mMockCal, getDoubleClickDuration(_)).WillOnce(DoDefault());
- EXPECT_CALL(*mMockCal, getHeavyClickDuration(_)).WillOnce(DoDefault());
-
- EXPECT_CALL(*mMockApi, setLpTriggerEffect(1)).WillOnce(::testing::Return(true));
-
- createVibrator(std::move(mockapi), std::move(mockcal), false);
-}
-
-TEST_F(VibratorTest, on) {
- EffectDuration duration = std::rand();
- Sequence s1, s2, s3;
-
- EXPECT_CALL(*mMockApi, setCtrlLoop(AnyOf(0, 1)))
- .InSequence(s1)
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(*mMockApi, setMode("rtp")).InSequence(s2).WillOnce(::testing::Return(true));
- EXPECT_CALL(*mMockApi, setDuration(duration)).InSequence(s3).WillOnce(::testing::Return(true));
- EXPECT_CALL(*mMockApi, setActivate(true))
- .InSequence(s1, s2, s3)
- .WillOnce(::testing::Return(true));
-
- EXPECT_EQ(Status::OK, mVibrator->on(duration));
-}
-
-TEST_F(VibratorTest, off) {
- EXPECT_CALL(*mMockApi, setActivate(false)).WillOnce(::testing::Return(true));
-
- EXPECT_EQ(Status::OK, mVibrator->off());
-}
-
-TEST_F(VibratorTest, supportsAmplitudeControl_supported) {
- EXPECT_CALL(*mMockApi, hasRtpInput()).WillOnce(::testing::Return(true));
-
- EXPECT_EQ(true, mVibrator->supportsAmplitudeControl());
-}
-
-TEST_F(VibratorTest, supportsAmplitudeControl_unsupported) {
- EXPECT_CALL(*mMockApi, hasRtpInput()).WillOnce(::testing::Return(false));
-
- EXPECT_EQ(false, mVibrator->supportsAmplitudeControl());
-}
-
-TEST_F(VibratorTest, setAmplitude) {
- EffectAmplitude amplitude = std::rand();
-
- EXPECT_CALL(*mMockApi, setRtpInput(amplitudeToRtpInput(amplitude)))
- .WillOnce(::testing::Return(true));
-
- EXPECT_EQ(Status::OK, mVibrator->setAmplitude(amplitude));
-}
-
-TEST_P(VibratorTest, perform) {
- auto param = GetParam();
- auto effect = std::get<0>(param);
- auto strength = std::get<1>(param);
- auto seqIter = EFFECT_SEQUENCES.find(param);
- auto durIter = mEffectDurations.find(effect);
- EffectDuration duration;
-
- if (seqIter != EFFECT_SEQUENCES.end() && durIter != mEffectDurations.end()) {
- auto sequence = std::get<0>(seqIter->second);
- auto scale = std::get<1>(seqIter->second);
- Sequence s1, s2, s3, s4, s5;
-
- duration = durIter->second;
-
- EXPECT_CALL(*mMockApi, setSequencer(sequence))
- .InSequence(s1)
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(*mMockApi, setScale(scale)).InSequence(s2).WillOnce(::testing::Return(true));
- EXPECT_CALL(*mMockApi, setCtrlLoop(1)).InSequence(s3).WillOnce(::testing::Return(true));
- EXPECT_CALL(*mMockApi, setMode("waveform"))
- .InSequence(s4)
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(*mMockApi, setDuration(duration))
- .InSequence(s5)
- .WillOnce(::testing::Return(true));
-
- EXPECT_CALL(*mMockApi, setActivate(true))
- .InSequence(s1, s2, s3, s4, s5)
- .WillOnce(::testing::Return(true));
- } else {
- duration = 0;
- }
-
- mVibrator->perform_1_2(effect, strength, [&](Status status, uint32_t lengthMs) {
- if (duration) {
- EXPECT_EQ(Status::OK, status);
- EXPECT_EQ(duration, lengthMs);
- } else {
- EXPECT_EQ(Status::UNSUPPORTED_OPERATION, status);
- EXPECT_EQ(0, lengthMs);
- }
- });
-}
-
-INSTANTIATE_TEST_CASE_P(VibratorEffects, VibratorTest,
- Combine(ValuesIn(hidl_enum_range<Effect>().begin(),
- hidl_enum_range<Effect>().end()),
- ValuesIn(hidl_enum_range<EffectStrength>().begin(),
- hidl_enum_range<EffectStrength>().end())),
- [](const testing::TestParamInfo<VibratorTest::ParamType> &info) {
- auto effect = std::get<0>(info.param);
- auto strength = std::get<1>(info.param);
- return toString(effect) + "_" + toString(strength);
- });
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
diff --git a/vibrator/tests/types.h b/vibrator/tests/types.h
deleted file mode 100644
index 839653c..0000000
--- a/vibrator/tests/types.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.
- */
-#ifndef ANDROID_HARDWARE_VIBRATOR_TEST_TYPES_H
-#define ANDROID_HARDWARE_VIBRATOR_TEST_TYPES_H
-
-#include <android/hardware/vibrator/1.2/IVibrator.h>
-
-using EffectAmplitude = uint8_t;
-using EffectDuration = uint32_t;
-using EffectSequence = std::tuple<std::string, uint8_t>;
-using EffectTuple = std::tuple<::android::hardware::vibrator::V1_2::Effect,
- ::android::hardware::vibrator::V1_0::EffectStrength>;
-
-#endif // ANDROID_HARDWARE_VIBRATOR_TEST_TYPES_H
diff --git a/vibrator/tests/utils.h b/vibrator/tests/utils.h
deleted file mode 100644
index 5fe4b62..0000000
--- a/vibrator/tests/utils.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.
- */
-#ifndef ANDROID_HARDWARE_VIBRATOR_TEST_UTILS_H
-#define ANDROID_HARDWARE_VIBRATOR_TEST_UTILS_H
-
-#include <cmath>
-
-#include "types.h"
-
-static inline int32_t amplitudeToRtpInput(EffectAmplitude amplitude) {
- return std::round((amplitude - 1) / 254.0 * 127);
-}
-
-#endif // ANDROID_HARDWARE_VIBRATOR_TEST_UTILS_H
diff --git a/vibrator/utils.h b/vibrator/utils.h
deleted file mode 100644
index d7a86ca..0000000
--- a/vibrator/utils.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.
- */
-#ifndef ANDROID_HARDWARE_VIBRATOR_UTILS_H
-#define ANDROID_HARDWARE_VIBRATOR_UTILS_H
-
-namespace android {
-namespace hardware {
-namespace vibrator {
-namespace utils {
-
-// override for default behavior of printing as a character
-inline std::ostream &operator<<(std::ostream &stream, const int8_t value) {
- return stream << +value;
-}
-// override for default behavior of printing as a character
-inline std::ostream &operator<<(std::ostream &stream, const uint8_t value) {
- return stream << +value;
-}
-
-} // namespace utils
-} // namespace vibrator
-} // namespace hardware
-} // namespace android
-
-#endif // ANDROID_HARDWARE_VIBRATOR_UTILS_H