|
|
@ -1,37 +1,23 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 The LineageOS Project |
|
|
|
* Copyright (C) 2021 The LineageOS Project |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* SPDX-License-Identifier: Apache-2.0 |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
|
|
|
* You may obtain a copy of the License at |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
|
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
|
|
|
* limitations under the License. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#define LOG_TAG "android.hardware.light@2.0-service.samsung" |
|
|
|
|
|
|
|
|
|
|
|
#define LOG_TAG "android.hardware.lights-service.samsung" |
|
|
|
|
|
|
|
|
|
|
|
#include <android-base/stringprintf.h> |
|
|
|
#include <android-base/stringprintf.h> |
|
|
|
#include <iomanip> |
|
|
|
#include <fstream> |
|
|
|
|
|
|
|
|
|
|
|
#include "Light.h" |
|
|
|
#include "Lights.h" |
|
|
|
|
|
|
|
|
|
|
|
#define COLOR_MASK 0x00ffffff |
|
|
|
#define COLOR_MASK 0x00ffffff |
|
|
|
#define MAX_INPUT_BRIGHTNESS 255 |
|
|
|
#define MAX_INPUT_BRIGHTNESS 255 |
|
|
|
|
|
|
|
|
|
|
|
using android::hardware::light::V2_0::LightState; |
|
|
|
namespace aidl { |
|
|
|
using android::hardware::light::V2_0::Status; |
|
|
|
|
|
|
|
using android::hardware::light::V2_0::Type; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace android { |
|
|
|
namespace android { |
|
|
|
namespace hardware { |
|
|
|
namespace hardware { |
|
|
|
namespace light { |
|
|
|
namespace light { |
|
|
|
namespace V2_0 { |
|
|
|
|
|
|
|
namespace implementation { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Write value to path and close file. |
|
|
|
* Write value to path and close file. |
|
|
@ -51,26 +37,27 @@ static T get(const std::string& path, const T& def) { |
|
|
|
return file.fail() ? def : result; |
|
|
|
return file.fail() ? def : result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Light::Light() { |
|
|
|
Lights::Lights() { |
|
|
|
mLights.emplace(Type::BACKLIGHT, |
|
|
|
mLights.emplace(LightType::BACKLIGHT, |
|
|
|
std::bind(&Light::handleBacklight, this, std::placeholders::_1)); |
|
|
|
std::bind(&Lights::handleBacklight, this, std::placeholders::_1)); |
|
|
|
#ifdef BUTTON_BRIGHTNESS_NODE |
|
|
|
#ifdef BUTTON_BRIGHTNESS_NODE |
|
|
|
mLights.emplace(Type::BUTTONS, std::bind(&Light::handleButtons, this, std::placeholders::_1)); |
|
|
|
mLights.emplace(LightType::BUTTONS, std::bind(&Lights::handleButtons, this, std::placeholders::_1)); |
|
|
|
#endif /* BUTTON_BRIGHTNESS_NODE */ |
|
|
|
#endif /* BUTTON_BRIGHTNESS_NODE */ |
|
|
|
#ifdef LED_BLINK_NODE |
|
|
|
#ifdef LED_BLINK_NODE |
|
|
|
mLights.emplace(Type::BATTERY, std::bind(&Light::handleBattery, this, std::placeholders::_1)); |
|
|
|
mLights.emplace(LightType::BATTERY, std::bind(&Lights::handleBattery, this, std::placeholders::_1)); |
|
|
|
mLights.emplace(Type::NOTIFICATIONS, |
|
|
|
mLights.emplace(LightType::NOTIFICATIONS, |
|
|
|
std::bind(&Light::handleNotifications, this, std::placeholders::_1)); |
|
|
|
std::bind(&Lights::handleNotifications, this, std::placeholders::_1)); |
|
|
|
mLights.emplace(Type::ATTENTION, |
|
|
|
mLights.emplace(LightType::ATTENTION, |
|
|
|
std::bind(&Light::handleAttention, this, std::placeholders::_1)); |
|
|
|
std::bind(&Lights::handleAttention, this, std::placeholders::_1)); |
|
|
|
#endif /* LED_BLINK_NODE */ |
|
|
|
#endif /* LED_BLINK_NODE */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Return<Status> Light::setLight(Type type, const LightState& state) { |
|
|
|
ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state) { |
|
|
|
|
|
|
|
LightType type = static_cast<LightType>(id); |
|
|
|
auto it = mLights.find(type); |
|
|
|
auto it = mLights.find(type); |
|
|
|
|
|
|
|
|
|
|
|
if (it == mLights.end()) { |
|
|
|
if (it == mLights.end()) { |
|
|
|
return Status::LIGHT_NOT_SUPPORTED; |
|
|
|
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -80,10 +67,10 @@ Return<Status> Light::setLight(Type type, const LightState& state) { |
|
|
|
|
|
|
|
|
|
|
|
it->second(state); |
|
|
|
it->second(state); |
|
|
|
|
|
|
|
|
|
|
|
return Status::SUCCESS; |
|
|
|
return ndk::ScopedAStatus::ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Light::handleBacklight(const LightState& state) { |
|
|
|
void Lights::handleBacklight(const HwLightState& state) { |
|
|
|
uint32_t max_brightness = get(PANEL_MAX_BRIGHTNESS_NODE, MAX_INPUT_BRIGHTNESS); |
|
|
|
uint32_t max_brightness = get(PANEL_MAX_BRIGHTNESS_NODE, MAX_INPUT_BRIGHTNESS); |
|
|
|
uint32_t brightness = rgbToBrightness(state); |
|
|
|
uint32_t brightness = rgbToBrightness(state); |
|
|
|
|
|
|
|
|
|
|
@ -95,7 +82,7 @@ void Light::handleBacklight(const LightState& state) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef BUTTON_BRIGHTNESS_NODE |
|
|
|
#ifdef BUTTON_BRIGHTNESS_NODE |
|
|
|
void Light::handleButtons(const LightState& state) { |
|
|
|
void Lights::handleButtons(const HwLightState& state) { |
|
|
|
#ifdef VAR_BUTTON_BRIGHTNESS |
|
|
|
#ifdef VAR_BUTTON_BRIGHTNESS |
|
|
|
uint32_t brightness = rgbToBrightness(state); |
|
|
|
uint32_t brightness = rgbToBrightness(state); |
|
|
|
#else |
|
|
|
#else |
|
|
@ -107,24 +94,24 @@ void Light::handleButtons(const LightState& state) { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef LED_BLINK_NODE |
|
|
|
#ifdef LED_BLINK_NODE |
|
|
|
void Light::handleBattery(const LightState& state) { |
|
|
|
void Lights::handleBattery(const HwLightState& state) { |
|
|
|
mBatteryState = state; |
|
|
|
mBatteryState = state; |
|
|
|
setNotificationLED(); |
|
|
|
setNotificationLED(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Light::handleNotifications(const LightState& state) { |
|
|
|
void Lights::handleNotifications(const HwLightState& state) { |
|
|
|
mNotificationState = state; |
|
|
|
mNotificationState = state; |
|
|
|
setNotificationLED(); |
|
|
|
setNotificationLED(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Light::handleAttention(const LightState& state) { |
|
|
|
void Lights::handleAttention(const HwLightState& state) { |
|
|
|
mAttentionState = state; |
|
|
|
mAttentionState = state; |
|
|
|
setNotificationLED(); |
|
|
|
setNotificationLED(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Light::setNotificationLED() { |
|
|
|
void Lights::setNotificationLED() { |
|
|
|
int32_t adjusted_brightness = MAX_INPUT_BRIGHTNESS; |
|
|
|
int32_t adjusted_brightness = MAX_INPUT_BRIGHTNESS; |
|
|
|
LightState state; |
|
|
|
HwLightState state; |
|
|
|
#ifdef LED_BLN_NODE |
|
|
|
#ifdef LED_BLN_NODE |
|
|
|
bool bln = false; |
|
|
|
bool bln = false; |
|
|
|
#endif /* LED_BLN_NODE */ |
|
|
|
#endif /* LED_BLN_NODE */ |
|
|
@ -138,11 +125,11 @@ void Light::setNotificationLED() { |
|
|
|
} else if (mAttentionState.color & COLOR_MASK) { |
|
|
|
} else if (mAttentionState.color & COLOR_MASK) { |
|
|
|
adjusted_brightness = LED_BRIGHTNESS_ATTENTION; |
|
|
|
adjusted_brightness = LED_BRIGHTNESS_ATTENTION; |
|
|
|
state = mAttentionState; |
|
|
|
state = mAttentionState; |
|
|
|
if (state.flashMode == Flash::HARDWARE) { |
|
|
|
if (state.flashMode == FlashMode::HARDWARE) { |
|
|
|
if (state.flashOnMs > 0 && state.flashOffMs == 0) state.flashMode = Flash::NONE; |
|
|
|
if (state.flashOnMs > 0 && state.flashOffMs == 0) state.flashMode = FlashMode::NONE; |
|
|
|
state.color = 0x000000ff; |
|
|
|
state.color = 0x000000ff; |
|
|
|
} |
|
|
|
} |
|
|
|
if (state.flashMode == Flash::NONE) { |
|
|
|
if (state.flashMode == FlashMode::NONE) { |
|
|
|
state.color = 0; |
|
|
|
state.color = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (mBatteryState.color & COLOR_MASK) { |
|
|
|
} else if (mBatteryState.color & COLOR_MASK) { |
|
|
@ -153,13 +140,13 @@ void Light::setNotificationLED() { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (state.flashMode == Flash::NONE) { |
|
|
|
if (state.flashMode == FlashMode::NONE) { |
|
|
|
state.flashOnMs = 0; |
|
|
|
state.flashOnMs = 0; |
|
|
|
state.flashOffMs = 0; |
|
|
|
state.flashOffMs = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state.color = calibrateColor(state.color & COLOR_MASK, adjusted_brightness); |
|
|
|
state.color = calibrateColor(state.color & COLOR_MASK, adjusted_brightness); |
|
|
|
set(LED_BLINK_NODE, android::base::StringPrintf("0x%08x %d %d", state.color, state.flashOnMs, |
|
|
|
set(LED_BLINK_NODE, ::android::base::StringPrintf("0x%08x %d %d", state.color, state.flashOnMs, |
|
|
|
state.flashOffMs)); |
|
|
|
state.flashOffMs)); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef LED_BLN_NODE |
|
|
|
#ifdef LED_BLN_NODE |
|
|
@ -169,7 +156,7 @@ void Light::setNotificationLED() { |
|
|
|
#endif /* LED_BLN_NODE */ |
|
|
|
#endif /* LED_BLN_NODE */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t Light::calibrateColor(uint32_t color, int32_t brightness) { |
|
|
|
uint32_t Lights::calibrateColor(uint32_t color, int32_t brightness) { |
|
|
|
uint32_t red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R; |
|
|
|
uint32_t red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R; |
|
|
|
uint32_t green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G; |
|
|
|
uint32_t green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G; |
|
|
|
uint32_t blue = (color & 0xFF) * LED_ADJUSTMENT_B; |
|
|
|
uint32_t blue = (color & 0xFF) * LED_ADJUSTMENT_B; |
|
|
@ -179,27 +166,24 @@ uint32_t Light::calibrateColor(uint32_t color, int32_t brightness) { |
|
|
|
} |
|
|
|
} |
|
|
|
#endif /* LED_BLINK_NODE */ |
|
|
|
#endif /* LED_BLINK_NODE */ |
|
|
|
|
|
|
|
|
|
|
|
Return<void> Light::getSupportedTypes(getSupportedTypes_cb _hidl_cb) { |
|
|
|
#define AutoHwLight(light) {.id = (int32_t)light, .type = light, .ordinal = 0} |
|
|
|
std::vector<Type> types; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight> *_aidl_return) { |
|
|
|
for (auto const& light : mLights) { |
|
|
|
for (auto const& light : mLights) { |
|
|
|
types.push_back(light.first); |
|
|
|
_aidl_return->push_back(AutoHwLight(light.first)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_hidl_cb(types); |
|
|
|
return ndk::ScopedAStatus::ok(); |
|
|
|
|
|
|
|
|
|
|
|
return Void(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t Light::rgbToBrightness(const LightState& state) { |
|
|
|
uint32_t Lights::rgbToBrightness(const HwLightState& state) { |
|
|
|
uint32_t color = state.color & COLOR_MASK; |
|
|
|
uint32_t color = state.color & COLOR_MASK; |
|
|
|
|
|
|
|
|
|
|
|
return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) + (29 * (color & 0xff))) >> |
|
|
|
return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) + (29 * (color & 0xff))) >> |
|
|
|
8; |
|
|
|
8; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace implementation
|
|
|
|
|
|
|
|
} // namespace V2_0
|
|
|
|
|
|
|
|
} // namespace light
|
|
|
|
} // namespace light
|
|
|
|
} // namespace hardware
|
|
|
|
} // namespace hardware
|
|
|
|
} // namespace android
|
|
|
|
} // namespace android
|
|
|
|
|
|
|
|
} // namespace aidl
|