From b0c20e99a12f075a9a3289b05faf4fff8e0eb47f Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Wed, 20 Dec 2017 14:50:53 -0800 Subject: [PATCH] Add debug output for lights. As an example and also to expose which lights are registered easily. Note, this is all the information that we can print given the libhardware lights interface. Bug: 70846424 Test: lshal debug Change-Id: I5f55e3e64149fc63a45ab9dab94d5fea27bb61da --- light/2.0/default/Light.cpp | 24 ++++++++++++++++++++++++ light/2.0/default/Light.h | 5 +++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/light/2.0/default/Light.cpp b/light/2.0/default/Light.cpp index cde1536633..5484d2db43 100644 --- a/light/2.0/default/Light.cpp +++ b/light/2.0/default/Light.cpp @@ -18,6 +18,8 @@ #include +#include + #include "Light.h" namespace android { @@ -107,6 +109,28 @@ const static std::map kLogicalLights = { {Type::WIFI, LIGHT_ID_WIFI} }; +Return Light::debug(const hidl_handle& handle, const hidl_vec& /* options */) { + if (handle == nullptr || handle->numFds < 1) { + ALOGE("debug called with no handle\n"); + return Void(); + } + + int fd = handle->data[0]; + if (fd < 0) { + ALOGE("invalid FD: %d\n", handle->data[0]); + return Void(); + } + + dprintf(fd, "The following lights are registered: "); + for (auto const& pair : mLights) { + const Type type = pair.first; + dprintf(fd, "%s,", kLogicalLights.at(type)); + } + dprintf(fd, ".\n"); + fsync(fd); + return Void(); +} + light_device_t* getLightDevice(const char* name) { light_device_t* lightDevice; const hw_module_t* hwModule = NULL; diff --git a/light/2.0/default/Light.h b/light/2.0/default/Light.h index 8987036f99..8851461de1 100644 --- a/light/2.0/default/Light.h +++ b/light/2.0/default/Light.h @@ -42,11 +42,12 @@ using ::android::sp; struct Light : public ILight { Light(std::map &&lights); - // Methods from ::android::hardware::light::V2_0::ILight follow. Return setLight(Type type, const LightState& state) override; Return getSupportedTypes(getSupportedTypes_cb _hidl_cb) override; -private: + Return debug(const hidl_handle& handle, const hidl_vec& options) override; + + private: std::map mLights; };