summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2017-01-31 18:34:15 +0000
committerMichael Wright <michaelwr@google.com>2017-03-20 12:00:26 +0000
commit1ca70b42f894dc113c958a962163e07912c8e8ac (patch)
treef135663bac26c77053c7e57d36572fb1d90e6522
parent28cf8e7a81f0406d9dd7e7358ef04f4de6e7a015 (diff)
downloadmarlin-1ca70b42f894dc113c958a962163e07912c8e8ac.tar.gz
Custom Vibrator implementation
Add support for new amplitude controls. Test: Manual testing with vendor/google_experimental/users/michaelwr/Vibrator & adb shell /data/nativetest/vibrator_hidl_hal_test/vibrator_hidl_hal_test Change-Id: I7e8c489169d2955d3c5fcc7e6aa0e9aa12bf88a2
-rw-r--r--Android.bp3
-rw-r--r--device-common.mk2
-rw-r--r--init.common.rc3
-rw-r--r--sepolicy/file_contexts2
-rw-r--r--vibrator/Android.bp30
-rw-r--r--vibrator/Vibrator.cpp94
-rw-r--r--vibrator/Vibrator.h51
-rw-r--r--vibrator/android.hardware.vibrator@1.0-service.marlin.rc4
-rw-r--r--vibrator/service.cpp59
9 files changed, 247 insertions, 1 deletions
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 00000000..97a24c8d
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,3 @@
+subdirs = [
+ "vibrator",
+]
diff --git a/device-common.mk b/device-common.mk
index cdc36fce..0454983f 100644
--- a/device-common.mk
+++ b/device-common.mk
@@ -463,7 +463,7 @@ PRODUCT_PACKAGES += \
# Vibrator
PRODUCT_PACKAGES += \
- android.hardware.vibrator@1.0-impl
+ android.hardware.vibrator@1.0-service.marlin \
# VR
PRODUCT_PACKAGES += \
diff --git a/init.common.rc b/init.common.rc
index 53e174b9..5d1d72df 100644
--- a/init.common.rc
+++ b/init.common.rc
@@ -396,6 +396,9 @@ on boot
chown system system /sys/class/leds/blue/rgb_start
chown system system /sys/class/leds/lcd-backlight/low_persistence
+ # Permission for vibrator amplitude
+ chown system system /sys/class/timed_output/vibrator/voltage_level
+
# Create QMUX deamon socket area
mkdir /dev/socket/qmux_radio 0770 radio radio
chmod 2770 /dev/socket/qmux_radio
diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts
index 69c775cd..2ecfb2c6 100644
--- a/sepolicy/file_contexts
+++ b/sepolicy/file_contexts
@@ -113,6 +113,7 @@
/vendor/bin/hw/android\.hardware\.drm@1\.0-service.widevine u:object_r:hal_drm_widevine_exec:s0
/vendor/bin/hw/android\.hardware\.dumpstate@1\.0-service.marlin u:object_r:hal_dumpstate_impl_exec:s0
/vendor/bin/hw/android\.hardware\.usb@1\.0-service.marlin u:object_r:hal_usb_default_exec:s0
+/vendor/bin/hw/android\.hardware\.vibrator@1\.0-service.marlin u:object_r:hal_vibrator_default_exec:s0
/vendor/bin/msm_irqbalance u:object_r:irqbalance_exec:s0
/vendor/bin/nanohub_slpi u:object_r:nanohub_slpi_exec:s0
/vendor/bin/perfd u:object_r:perfd_exec:s0
@@ -165,6 +166,7 @@
/sys/module/lpm_levels/parameters(/.*)? u:object_r:sysfs_power_management:s0
/sys/devices/soc/qpnp-fg-[0-9a-f]+/power_supply/bms/capacity u:object_r:sysfs_batteryinfo:s0
/sys/devices/soc/qpnp-smbcharger-[0-9a-f]+/power_supply/battery/capacity u:object_r:sysfs_batteryinfo:s0
+/sys/devices/virtual/timed_output/vibrator/voltage_level u:object_r:sysfs_vibrator:s0
# debugfs
/sys/kernel/debug/msm_core(/.*)? u:object_r:debugfs_msm_core:s0
diff --git a/vibrator/Android.bp b/vibrator/Android.bp
new file mode 100644
index 00000000..26cd093d
--- /dev/null
+++ b/vibrator/Android.bp
@@ -0,0 +1,30 @@
+//
+// 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_binary {
+ name: "android.hardware.vibrator@1.0-service.marlin",
+ relative_install_path: "hw",
+ init_rc: ["android.hardware.vibrator@1.0-service.marlin.rc"],
+ srcs: ["service.cpp", "Vibrator.cpp"],
+ shared_libs: [
+ "libhidlbase",
+ "libhidltransport",
+ "liblog",
+ "libhwbinder",
+ "libutils",
+ "libhardware",
+ "android.hardware.vibrator@1.0",
+ ],
+ proprietary: true,
+}
diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp
new file mode 100644
index 00000000..29115764
--- /dev/null
+++ b/vibrator/Vibrator.cpp
@@ -0,0 +1,94 @@
+/*
+ * 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 <log/log.h>
+
+#include <hardware/hardware.h>
+#include <hardware/vibrator.h>
+
+#include "Vibrator.h"
+
+#include <cinttypes>
+#include <cmath>
+#include <iostream>
+#include <fstream>
+
+
+namespace android {
+namespace hardware {
+namespace vibrator {
+namespace V1_0 {
+namespace implementation {
+
+static constexpr int MAX_VOLTAGE = 3596;
+static constexpr int MIN_VOLTAGE = 116;
+
+Vibrator::Vibrator(std::ofstream&& enable, std::ofstream&& amplitude) :
+ mEnable(std::move(enable)),
+ mAmplitude(std::move(amplitude)) {}
+
+// Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
+Return<Status> Vibrator::on(uint32_t timeout_ms) {
+ mEnable << timeout_ms << std::endl;
+ if (!mEnable) {
+ ALOGE("Failed to turn vibrator on (%d): %s", errno, strerror(errno));
+ return Status::UNKNOWN_ERROR;
+ }
+ return Status::OK;
+}
+
+Return<Status> Vibrator::off() {
+ mEnable << 0 << std::endl;
+ if (!mEnable) {
+ ALOGE("Failed to turn vibrator off (%d): %s", errno, strerror(errno));
+ return Status::UNKNOWN_ERROR;
+ }
+ return Status::OK;
+}
+
+Return<bool> Vibrator::supportsAmplitudeControl() {
+ return true;
+}
+
+Return<Status> Vibrator::setAmplitude(uint8_t amplitude) {
+ if (amplitude == 0) {
+ return Status::BAD_VALUE;
+ }
+ // Scale the voltage such that an amplitude of 1 is MIN_VOLTAGE, an amplitude of 255 is
+ // MAX_VOLTAGE, and there are equal steps for every value in between.
+ long voltage =
+ std::lround((amplitude - 1) / 254.0 * (MAX_VOLTAGE - MIN_VOLTAGE) + MIN_VOLTAGE);
+ ALOGE("Setting amplitude to: %ld", voltage);
+ mAmplitude << voltage << std::endl;
+ if (!mAmplitude) {
+ ALOGE("Failed to set amplitude (%d): %s", errno, strerror(errno));
+ return Status::UNKNOWN_ERROR;
+ }
+ return Status::OK;
+}
+
+Return<void> Vibrator::perform(Effect, EffectStrength, perform_cb _hidl_cb) {
+ _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
+ return Void();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace vibrator
+} // namespace hardware
+} // namespace android
diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h
new file mode 100644
index 00000000..f7bed1cf
--- /dev/null
+++ b/vibrator/Vibrator.h
@@ -0,0 +1,51 @@
+/*
+ * 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_0_VIBRATOR_H
+#define ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H
+
+#include <android/hardware/vibrator/1.0/IVibrator.h>
+#include <hidl/Status.h>
+
+#include <fstream>
+
+namespace android {
+namespace hardware {
+namespace vibrator {
+namespace V1_0 {
+namespace implementation {
+
+class Vibrator : public IVibrator {
+public:
+ Vibrator(std::ofstream&& enable, std::ofstream&& amplitude);
+
+ // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
+ Return<Status> on(uint32_t timeoutMs) override;
+ Return<Status> off() override;
+ Return<bool> supportsAmplitudeControl() override;
+ Return<Status> setAmplitude(uint8_t amplitude) override;
+ Return<void> perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
+
+private:
+ std::ofstream mEnable;
+ std::ofstream mAmplitude;
+};
+} // namespace implementation
+} // namespace V1_0
+} // namespace vibrator
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H
diff --git a/vibrator/android.hardware.vibrator@1.0-service.marlin.rc b/vibrator/android.hardware.vibrator@1.0-service.marlin.rc
new file mode 100644
index 00000000..a6aff117
--- /dev/null
+++ b/vibrator/android.hardware.vibrator@1.0-service.marlin.rc
@@ -0,0 +1,4 @@
+service vibrator-1-0 /vendor/bin/hw/android.hardware.vibrator@1.0-service.marlin
+ class hal
+ user system
+ group system readproc
diff --git a/vibrator/service.cpp b/vibrator/service.cpp
new file mode 100644
index 00000000..0b7ed355
--- /dev/null
+++ b/vibrator/service.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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.0-service.marlin"
+
+#include <android/hardware/vibrator/1.0/IVibrator.h>
+#include <hidl/HidlSupport.h>
+#include <hidl/HidlTransportSupport.h>
+#include <utils/Errors.h>
+#include <utils/StrongPointer.h>
+
+#include "Vibrator.h"
+
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
+using android::hardware::vibrator::V1_0::IVibrator;
+using android::hardware::vibrator::V1_0::implementation::Vibrator;
+using namespace android;
+
+static const char *ENABLE_PATH = "/sys/class/timed_output/vibrator/enable";
+static const char *AMPLITUDE_PATH = "/sys/class/timed_output/vibrator/voltage_level";
+
+status_t registerVibratorService() {
+ std::ofstream enable{ENABLE_PATH};
+ if (!enable) {
+ int error = errno;
+ ALOGE("Failed to open %s (%d): %s", ENABLE_PATH, error, strerror(error));
+ return -error;
+ }
+
+ std::ofstream amplitude{AMPLITUDE_PATH};
+ if (!amplitude) {
+ int error = errno;
+ ALOGE("Failed to open %s (%d): %s", AMPLITUDE_PATH, error, strerror(error));
+ return -error;
+ }
+
+ sp<IVibrator> vibrator = new Vibrator(std::move(enable), std::move(amplitude));
+ vibrator->registerAsService();
+ return OK;
+}
+
+int main() {
+ registerVibratorService();
+ configureRpcThreadpool(1, true);
+ joinRpcThreadpool();
+}