diff options
Diffstat (limited to 'light/Light.h')
-rw-r--r-- | light/Light.h | 46 |
1 files changed, 29 insertions, 17 deletions
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 <android/hardware/light/2.0/ILight.h> -#include <hardware/lights.h> -#include <hidl/Status.h> -#include <map> -#include <mutex> + +#include <unordered_map> 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<Status> setLight(Type type, const LightState& state) override; + Return<void> getSupportedTypes(getSupportedTypes_cb _hidl_cb) override; - Return<Status> setLight(Type type, const LightState& state) override; - Return<void> 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<Type, std::function<void(Type type, const LightState&)>> 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<std::pair<Type, LightState>, 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 |