summaryrefslogtreecommitdiff
path: root/vibrator/aidl/default/Vibrator.cpp
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-11-05 13:29:10 -0800
committerSteven Moreland <smoreland@google.com>2019-11-05 13:29:10 -0800
commitd91e449020e413f31f94dee79d7f0acf1797e30c (patch)
tree5e965a7078e4808fa096d9f1ae00868436dbc421 /vibrator/aidl/default/Vibrator.cpp
parent2b4209ff9395d7d346e8f7377a5bd98a8358978b (diff)
s/staidl/aidl/
staidl is a term I made up w/o precedence. aidl is clearer and more consistent w/ practices elsewhere. Bug: 141828236 Test: N/A Change-Id: I3f044ddf470b63956f2aa496ae9fe9e5893f479a
Diffstat (limited to 'vibrator/aidl/default/Vibrator.cpp')
-rw-r--r--vibrator/aidl/default/Vibrator.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/vibrator/aidl/default/Vibrator.cpp b/vibrator/aidl/default/Vibrator.cpp
new file mode 100644
index 0000000000..cdf8e0963b
--- /dev/null
+++ b/vibrator/aidl/default/Vibrator.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+#include "Vibrator.h"
+
+#include <android-base/logging.h>
+#include <thread>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace vibrator {
+
+ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
+ LOG(INFO) << "Vibrator reporting capabilities";
+ *_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK |
+ IVibrator::CAP_AMPLITUDE_CONTROL | IVibrator::CAP_EXTERNAL_CONTROL;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Vibrator::off() {
+ LOG(INFO) << "Vibrator off";
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
+ const std::shared_ptr<IVibratorCallback>& callback) {
+ LOG(INFO) << "Vibrator on for timeoutMs: " << timeoutMs;
+ if (callback != nullptr) {
+ std::thread([=] {
+ LOG(INFO) << "Starting on on another thread";
+ usleep(timeoutMs * 1000);
+ LOG(INFO) << "Notifying on complete";
+ callback->onComplete();
+ }).detach();
+ }
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength,
+ const std::shared_ptr<IVibratorCallback>& callback,
+ int32_t* _aidl_return) {
+ LOG(INFO) << "Vibrator perform";
+
+ if (effect != Effect::CLICK && effect != Effect::TICK) {
+ return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
+ }
+ if (strength != EffectStrength::LIGHT && strength != EffectStrength::MEDIUM &&
+ strength != EffectStrength::STRONG) {
+ return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
+ }
+
+ constexpr size_t kEffectMillis = 100;
+
+ if (callback != nullptr) {
+ std::thread([=] {
+ LOG(INFO) << "Starting perform on another thread";
+ usleep(kEffectMillis * 1000);
+ LOG(INFO) << "Notifying perform complete";
+ callback->onComplete();
+ }).detach();
+ }
+
+ *_aidl_return = kEffectMillis;
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Vibrator::setAmplitude(int32_t amplitude) {
+ LOG(INFO) << "Vibrator set amplitude: " << amplitude;
+ if (amplitude <= 0 || amplitude > 255) {
+ return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
+ }
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) {
+ LOG(INFO) << "Vibrator set external control: " << enabled;
+ return ndk::ScopedAStatus::ok();
+}
+
+} // namespace vibrator
+} // namespace hardware
+} // namespace android
+} // namespace aidl