Add lightsctl-aidl command to debug lights aidl hal

This commit is contained in:
Pierre-Hugues Husson 2022-05-04 12:43:08 -04:00
parent deaf416f56
commit be9a39aff4
2 changed files with 84 additions and 0 deletions

View File

@ -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",
],
}

71
cmds/lightsctl-aidl.cpp Normal file
View File

@ -0,0 +1,71 @@
#include <iostream>
#include <android/hardware/light/ILights.h>
#include <binder/IServiceManager.h>
using ::android::hardware::light::ILights;
using ::android::sp;
int main(int argc, char **argv) {
auto svc = android::waitForVintfService<ILights>();
std::vector<android::hardware::light::HwLight> 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;
}