From c279339ab927e2bdb77aa42973ef3e320c025364 Mon Sep 17 00:00:00 2001 From: dianlujitao Date: Thu, 6 Feb 2020 23:02:18 +0800 Subject: sdm660-common: Improve lights HAL * Use libbase logging and file utils * Read max brightness from sysfs * Convert constants to constexpr * Move helper functions to anonymous namespace * Bug fixes * Remove redundant chmod * Start the service after permissions are set up because it reads max brightness in constructor. Change-Id: I145d393c785e182060c5651e796d489f8c4d697b [SQUASHME] Let's dejank paths a bit... Change-Id: Ifd3d05588b0271e7a361aa4c7374a91fe5639a1f --- light/Light.h | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'light/Light.h') diff --git a/light/Light.h b/light/Light.h index 311b7de..8427148 100644 --- a/light/Light.h +++ b/light/Light.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The LineageOS Project + * Copyright (C) 2017-2020 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H -#define ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H + +#pragma once #include -#include -#include -#include -#include + +#include namespace android { namespace hardware { @@ -29,22 +27,38 @@ namespace V2_0 { namespace implementation { using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::hidl_vec; using ::android::hardware::light::V2_0::ILight; using ::android::hardware::light::V2_0::LightState; using ::android::hardware::light::V2_0::Status; using ::android::hardware::light::V2_0::Type; class Light : public ILight { - public: - Light(); + public: + Light(); + + Return setLight(Type type, const LightState& state) override; + Return getSupportedTypes(getSupportedTypes_cb _hidl_cb) override; - Return setLight(Type type, const LightState& state) override; - Return getSupportedTypes(getSupportedTypes_cb _hidl_cb) override; + private: + void setLightBacklight(Type type, const LightState& state); + void setLightNotification(Type type, const LightState& state); + void applyNotificationState(const LightState& state); - private: - std::mutex globalLock; + uint32_t max_led_brightness_; + uint32_t max_screen_brightness_; + + std::unordered_map> lights_{ + {Type::ATTENTION, [this](auto&&... args) { setLightNotification(args...); }}, + {Type::BACKLIGHT, [this](auto&&... args) { setLightBacklight(args...); }}, + {Type::BATTERY, [this](auto&&... args) { setLightNotification(args...); }}, + {Type::NOTIFICATIONS, [this](auto&&... args) { setLightNotification(args...); }}}; + + // Keep sorted in the order of importance. + std::array, 3> notif_states_ = {{ + {Type::ATTENTION, {}}, + {Type::NOTIFICATIONS, {}}, + {Type::BATTERY, {}}, + }}; }; } // namespace implementation @@ -52,5 +66,3 @@ class Light : public ILight { } // namespace light } // namespace hardware } // namespace android - -#endif // ANDROID_HARDWARE_LIGHT_V2_0_LIGHT_H -- cgit v1.2.3