From be9a39aff4fa99c4d3e1d9e7f75fbb9b1131f7ea Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Wed, 4 May 2022 12:43:08 -0400 Subject: [PATCH] Add lightsctl-aidl command to debug lights aidl hal --- cmds/Android.bp | 13 ++++++++ cmds/lightsctl-aidl.cpp | 71 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 cmds/lightsctl-aidl.cpp diff --git a/cmds/Android.bp b/cmds/Android.bp index 520c59f..e3748f9 100644 --- a/cmds/Android.bp +++ b/cmds/Android.bp @@ -241,3 +241,16 @@ cc_binary { "libhidlbase", ], } + +cc_binary { + name: "lightsctl-aidl", + srcs: [ + "lightsctl-aidl.cpp", + ], + shared_libs: [ + "android.hardware.light-V1-cpp", + "libutils", + "libhidlbase", + "libbinder", + ], +} diff --git a/cmds/lightsctl-aidl.cpp b/cmds/lightsctl-aidl.cpp new file mode 100644 index 0000000..02927b2 --- /dev/null +++ b/cmds/lightsctl-aidl.cpp @@ -0,0 +1,71 @@ +#include +#include +#include + +using ::android::hardware::light::ILights; +using ::android::sp; + +int main(int argc, char **argv) { + auto svc = android::waitForVintfService(); + std::vector lights; + svc->getLights(&lights); + for(const auto& l : lights) { + std::cout << "Got light " << l.id << std::endl; + std::cout << " " << l.ordinal << std::endl; + std::cout << " " << toString(l.type) << std::endl; + } + if(argc <= 1) return 0; + if(argc != 3 && argc != 6) return 1; + + std::string typeArg(argv[1]); + android::hardware::light::LightType type; + if(typeArg == "BACKLIGHT") + type = android::hardware::light::LightType::BACKLIGHT; + if(typeArg == "KEYBOARD") + type = android::hardware::light::LightType::KEYBOARD; + if(typeArg == "BUTTONS") + type = android::hardware::light::LightType::BUTTONS; + if(typeArg == "BATTERY") + type = android::hardware::light::LightType::BATTERY; + if(typeArg == "NOTIFICATIONS") + type = android::hardware::light::LightType::NOTIFICATIONS; + if(typeArg == "ATTENTION") + type = android::hardware::light::LightType::ATTENTION; + if(typeArg == "BLUETOOTH") + type = android::hardware::light::LightType::BLUETOOTH; + if(typeArg == "WIFI") + type = android::hardware::light::LightType::WIFI; + std::cout << "Set request type " << toString(type) << std::endl; + + int lightId = -1; + for(const auto& l : lights) { + if(l.type == type) { + lightId = l.id; + std::cout << "Got matching light " << l.id << std::endl; + std::cout << " " << l.ordinal << std::endl; + std::cout << " " << toString(l.type) << std::endl; + } + } + + android::hardware::light::HwLightState state; + state.color = (uint32_t)strtoll(argv[2], NULL, 16); + state.flashMode = android::hardware::light::FlashMode::NONE; + state.brightnessMode = android::hardware::light::BrightnessMode::USER; + + if(argc == 6) { + std::string flashArg(argv[3]); + if(flashArg == "NONE") + state.flashMode = android::hardware::light::FlashMode::NONE; + if(flashArg == "TIMED") + state.flashMode = android::hardware::light::FlashMode::TIMED; + if(flashArg == "HARDWARE") + state.flashMode = android::hardware::light::FlashMode::HARDWARE; + + state.flashOnMs = atoi(argv[4]); + state.flashOffMs = atoi(argv[5]); + } + std::cout << "Set flash type to " << toString(state.flashMode) << std::endl; + + auto ret = svc->setLightState(lightId, state); + std::cout << "Set light returned " << ret << std::endl; +}