summaryrefslogtreecommitdiff
path: root/light/Light.h
diff options
context:
space:
mode:
authordianlujitao <dianlujitao@lineageos.org>2020-02-06 23:02:18 +0800
committerMichael Bestas <mkbestas@lineageos.org>2020-04-30 00:49:34 +0300
commitc279339ab927e2bdb77aa42973ef3e320c025364 (patch)
treee0792b6e068209cc5bb2a5f12aa3039a625fba6d /light/Light.h
parent938bdfae0a0a69e765d39121ba18de111df28eaa (diff)
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
Diffstat (limited to 'light/Light.h')
-rw-r--r--light/Light.h46
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