summaryrefslogtreecommitdiff
path: root/cmds/idlcli/vibrator.h
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/idlcli/vibrator.h')
-rw-r--r--cmds/idlcli/vibrator.h59
1 files changed, 44 insertions, 15 deletions
diff --git a/cmds/idlcli/vibrator.h b/cmds/idlcli/vibrator.h
index ca5142dee9..dfbb8863bd 100644
--- a/cmds/idlcli/vibrator.h
+++ b/cmds/idlcli/vibrator.h
@@ -13,20 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_
-#define FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_
+#pragma once
+#include <future>
+
+#include <aidl/android/hardware/vibrator/BnVibratorCallback.h>
#include <aidl/android/hardware/vibrator/IVibrator.h>
+#include <aidl/android/hardware/vibrator/IVibratorManager.h>
#include <android/binder_manager.h>
+#include <android/binder_process.h>
#include <android/hardware/vibrator/1.3/IVibrator.h>
+#include "IdlCli.h"
#include "utils.h"
-#include "log/log.h"
-
namespace android {
using hardware::Return;
+using idlcli::IdlCli;
static constexpr int NUM_TRIES = 2;
@@ -43,20 +47,34 @@ inline ndk::ScopedAStatus NullptrStatus() {
}
template <typename I>
-inline auto getService() {
- return I::getService();
+inline auto getService(std::string name) {
+ const auto instance = std::string() + I::descriptor + "/" + name;
+ auto vibBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str()));
+ return I::fromBinder(vibBinder);
}
template <>
-inline auto getService<aidl::android::hardware::vibrator::IVibrator>() {
- const auto instance =
- std::string() + aidl::android::hardware::vibrator::IVibrator::descriptor + "/default";
- auto vibBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str()));
- return aidl::android::hardware::vibrator::IVibrator::fromBinder(vibBinder);
+inline auto getService<android::hardware::vibrator::V1_0::IVibrator>(std::string name) {
+ return android::hardware::vibrator::V1_0::IVibrator::getService(name);
+}
+
+template <>
+inline auto getService<android::hardware::vibrator::V1_1::IVibrator>(std::string name) {
+ return android::hardware::vibrator::V1_1::IVibrator::getService(name);
+}
+
+template <>
+inline auto getService<android::hardware::vibrator::V1_2::IVibrator>(std::string name) {
+ return android::hardware::vibrator::V1_2::IVibrator::getService(name);
+}
+
+template <>
+inline auto getService<android::hardware::vibrator::V1_3::IVibrator>(std::string name) {
+ return android::hardware::vibrator::V1_3::IVibrator::getService(name);
}
template <typename I>
-using shared_ptr = std::result_of_t<decltype(getService<I>)&()>;
+using shared_ptr = std::result_of_t<decltype(getService<I>)&(std::string)>;
template <typename I>
class HalWrapper {
@@ -64,7 +82,8 @@ public:
static std::unique_ptr<HalWrapper> Create() {
// Assume that if getService returns a nullptr, HAL is not available on the
// device.
- auto hal = getService<I>();
+ const auto name = IdlCli::Get().getName();
+ auto hal = getService<I>(name.empty() ? "default" : name);
return hal ? std::unique_ptr<HalWrapper>(new HalWrapper(std::move(hal))) : nullptr;
}
@@ -101,9 +120,19 @@ namespace V1_2 = ::android::hardware::vibrator::V1_2;
namespace V1_3 = ::android::hardware::vibrator::V1_3;
namespace aidl = ::aidl::android::hardware::vibrator;
+class VibratorCallback : public aidl::BnVibratorCallback {
+public:
+ ndk::ScopedAStatus onComplete() override {
+ mPromise.set_value();
+ return ndk::ScopedAStatus::ok();
+ }
+ void waitForComplete() { mPromise.get_future().wait(); }
+
+private:
+ std::promise<void> mPromise;
+};
+
} // namespace vibrator
} // namespace idlcli
} // namespace android
-
-#endif // FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_