Use IVibrator hidl service in dumpstate.
Bug: 33067126
Test: Dumpstate vibrator works. dumpstate_test passes.
Change-Id: I9a87755f695829482d072e538e4938f35f393ae4
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk
index 17b411f..897cfb1 100644
--- a/cmds/dumpstate/Android.mk
+++ b/cmds/dumpstate/Android.mk
@@ -102,7 +102,8 @@
LOCAL_MODULE := dumpstate
-LOCAL_SHARED_LIBRARIES := $(COMMON_SHARED_LIBRARIES)
+LOCAL_SHARED_LIBRARIES := $(COMMON_SHARED_LIBRARIES) \
+ android.hardware.vibrator@1.0
LOCAL_STATIC_LIBRARIES := $(COMMON_STATIC_LIBRARIES)
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index a0b0426..1e33439 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -43,6 +43,7 @@
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <android/hardware/dumpstate/1.0/IDumpstateDevice.h>
+#include <android/hardware/vibrator/1.0/IVibrator.h>
#include <cutils/native_handle.h>
#include <cutils/properties.h>
#include <hardware_legacy/power.h>
@@ -54,6 +55,10 @@
#include "DumpstateService.h"
#include "dumpstate.h"
+using ::android::hardware::dumpstate::V1_0::IDumpstateDevice;
+using ::android::hardware::vibrator::V1_0::IVibrator;
+using VibratorStatus = ::android::hardware::vibrator::V1_0::Status;
+
/* read before root is shed */
static char cmdline_buf[16384] = "(unknown)";
static const char *dump_traces_path = NULL;
@@ -1164,8 +1169,8 @@
printf("== Board\n");
printf("========================================================\n");
- android::sp<android::hardware::dumpstate::V1_0::IDumpstateDevice> dumpstate_device(
- android::hardware::dumpstate::V1_0::IDumpstateDevice::getService("DumpstateDevice"));
+ ::android::sp<IDumpstateDevice> dumpstate_device(
+ IDumpstateDevice::getService("DumpstateDevice"));
if (dumpstate_device == nullptr) {
// TODO: temporary workaround until devices on master implement it
MYLOGE("no IDumpstateDevice implementation; using legacy dumpstate_board()\n");
@@ -1586,12 +1591,21 @@
fclose(cmdline);
}
- /* open the vibrator before dropping root */
- std::unique_ptr<FILE, int(*)(FILE*)> vibrator(NULL, fclose);
+ ::android::sp<IVibrator> vibrator = nullptr;
if (do_vibrate) {
- vibrator.reset(fopen("/sys/class/timed_output/vibrator/enable", "we"));
- if (vibrator) {
- vibrate(vibrator.get(), 150);
+ vibrator = IVibrator::getService("vibrator");
+
+ if (vibrator != nullptr) {
+ // cancel previous vibration if any
+ ::android::hardware::Return<VibratorStatus> offStatus = vibrator->off();
+ if (!offStatus.isOk() || offStatus != VibratorStatus::OK) {
+ MYLOGE("Vibrator off failed.");
+ } else {
+ ::android::hardware::Return<VibratorStatus> onStatus = vibrator->on(150);
+ if (!onStatus.isOk() || onStatus != VibratorStatus::OK) {
+ MYLOGE("Vibrator on failed.");
+ }
+ }
}
}
@@ -1759,10 +1773,20 @@
}
/* vibrate a few but shortly times to let user know it's finished */
- if (vibrator) {
- for (int i = 0; i < 3; i++) {
- vibrate(vibrator.get(), 75);
- usleep((75 + 50) * 1000);
+ if (vibrator != nullptr) {
+ // in case dumpstate magically completes before the above vibration
+ ::android::hardware::Return<VibratorStatus> offStatus = vibrator->off();
+ if (!offStatus.isOk() || offStatus != VibratorStatus::OK) {
+ MYLOGE("Vibrator off failed.");
+ } else {
+ for (int i = 0; i < 3; i++) {
+ ::android::hardware::Return<VibratorStatus> onStatus = vibrator->on(75);
+ if (!onStatus.isOk() || onStatus != VibratorStatus::OK) {
+ MYLOGE("Vibrator on failed.");
+ break;
+ }
+ usleep((75 + 50) * 1000);
+ }
}
}
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index fcf0683..2c11c0c 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -402,9 +402,6 @@
/* Implemented by libdumpstate_board to dump board-specific info */
void dumpstate_board();
-/* Vibrates for a given durating (in milliseconds). */
-void vibrate(FILE* vibrator, int ms);
-
/* Checks if a given path is a directory. */
bool is_dir(const char* pathname);
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 5ee00c8..ee88705 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -1061,11 +1061,6 @@
}
}
-void vibrate(FILE* vibrator, int ms) {
- fprintf(vibrator, "%d\n", ms);
- fflush(vibrator);
-}
-
bool is_dir(const char* pathname) {
struct stat info;
if (stat(pathname, &info) == -1) {