Crosshatch: fix DumpstateMode validation.
The PROTO mode was added after initial HAL upgrade and is causing VTS
failures due to the way the DumpstateMode param is being validated.
Bug: 150873571
Test: atest VtsHalDumpstateV1_1TargetTest, verify PROTO tests pass now
Change-Id: Id6fb4ecbe5465ad3b9922a491920b0bf8ac7f528
(cherry picked from commit a83151a4fb70210509ef0ec5c9016afbb2ac8384)
diff --git a/dumpstate/DumpstateDevice.cpp b/dumpstate/DumpstateDevice.cpp
index f025faa..3a6396e 100755
--- a/dumpstate/DumpstateDevice.cpp
+++ b/dumpstate/DumpstateDevice.cpp
@@ -22,6 +22,7 @@
#include <android-base/unique_fd.h>
#include <cutils/properties.h>
#include <hidl/HidlBinderSupport.h>
+#include <hidl/HidlSupport.h>
#include <log/log.h>
#include <pthread.h>
@@ -384,13 +385,20 @@
return DumpstateStatus::ILLEGAL_ARGUMENT;
}
- if (mode == DumpstateMode::WEAR) {
+ bool isModeValid = false;
+ for (const auto dumpstateMode : hidl_enum_range<DumpstateMode>()) {
+ if (mode == dumpstateMode) {
+ isModeValid = true;
+ break;
+ }
+ }
+ if (!isModeValid) {
+ ALOGE("Invalid mode: %d\n", mode);
+ return DumpstateStatus::ILLEGAL_ARGUMENT;
+ } else if (mode == DumpstateMode::WEAR) {
// We aren't a Wear device.
ALOGE("Unsupported mode: %d\n", mode);
return DumpstateStatus::UNSUPPORTED_MODE;
- } else if (mode < DumpstateMode::FULL || mode > DumpstateMode::DEFAULT) {
- ALOGE("Invalid mode: %d\n", mode);
- return DumpstateStatus::ILLEGAL_ARGUMENT;
}
RunCommandToFd(fd, "Notify modem", {"/vendor/bin/modem_svc", "-s"}, CommandOptions::WithTimeout(1).Build());