mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 04:25:33 -04:00
[DNM] universal7885: import hardware/samsung deps
Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
parent
c25cedb10c
commit
76a69f9276
40 changed files with 3779 additions and 0 deletions
23
universal7885-common/aidl/light/Android.bp
Normal file
23
universal7885-common/aidl/light/Android.bp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// Copyright (C) 2021 The LineageOS Project
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.light-service.samsung",
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.light-service.samsung.rc"],
|
||||
vintf_fragments: ["android.hardware.light-service.samsung.xml"],
|
||||
local_include_dirs: ["include"],
|
||||
srcs: [
|
||||
"Lights.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"android.hardware.light-V1-ndk_platform",
|
||||
],
|
||||
vendor: true,
|
||||
}
|
||||
189
universal7885-common/aidl/light/Lights.cpp
Normal file
189
universal7885-common/aidl/light/Lights.cpp
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.lights-service.samsung"
|
||||
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "Lights.h"
|
||||
|
||||
#define COLOR_MASK 0x00ffffff
|
||||
#define MAX_INPUT_BRIGHTNESS 255
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
/*
|
||||
* Write value to path and close file.
|
||||
*/
|
||||
template <typename T>
|
||||
static void set(const std::string& path, const T& value) {
|
||||
std::ofstream file(path);
|
||||
file << value << std::endl;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T get(const std::string& path, const T& def) {
|
||||
std::ifstream file(path);
|
||||
T result;
|
||||
|
||||
file >> result;
|
||||
return file.fail() ? def : result;
|
||||
}
|
||||
|
||||
Lights::Lights() {
|
||||
mLights.emplace(LightType::BACKLIGHT,
|
||||
std::bind(&Lights::handleBacklight, this, std::placeholders::_1));
|
||||
#ifdef BUTTON_BRIGHTNESS_NODE
|
||||
mLights.emplace(LightType::BUTTONS, std::bind(&Lights::handleButtons, this, std::placeholders::_1));
|
||||
#endif /* BUTTON_BRIGHTNESS_NODE */
|
||||
#ifdef LED_BLINK_NODE
|
||||
mLights.emplace(LightType::BATTERY, std::bind(&Lights::handleBattery, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::NOTIFICATIONS,
|
||||
std::bind(&Lights::handleNotifications, this, std::placeholders::_1));
|
||||
mLights.emplace(LightType::ATTENTION,
|
||||
std::bind(&Lights::handleAttention, this, std::placeholders::_1));
|
||||
#endif /* LED_BLINK_NODE */
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state) {
|
||||
LightType type = static_cast<LightType>(id);
|
||||
auto it = mLights.find(type);
|
||||
|
||||
if (it == mLights.end()) {
|
||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lock global mutex until light state is updated.
|
||||
*/
|
||||
std::lock_guard<std::mutex> lock(mLock);
|
||||
|
||||
it->second(state);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
void Lights::handleBacklight(const HwLightState& state) {
|
||||
uint32_t max_brightness = get(PANEL_MAX_BRIGHTNESS_NODE, MAX_INPUT_BRIGHTNESS);
|
||||
uint32_t brightness = rgbToBrightness(state);
|
||||
|
||||
if (max_brightness != MAX_INPUT_BRIGHTNESS) {
|
||||
brightness = brightness * max_brightness / MAX_INPUT_BRIGHTNESS;
|
||||
}
|
||||
|
||||
set(PANEL_BRIGHTNESS_NODE, brightness);
|
||||
}
|
||||
|
||||
#ifdef BUTTON_BRIGHTNESS_NODE
|
||||
void Lights::handleButtons(const HwLightState& state) {
|
||||
#ifdef VAR_BUTTON_BRIGHTNESS
|
||||
uint32_t brightness = rgbToBrightness(state);
|
||||
#else
|
||||
uint32_t brightness = (state.color & COLOR_MASK) ? 1 : 0;
|
||||
#endif
|
||||
|
||||
set(BUTTON_BRIGHTNESS_NODE, brightness);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LED_BLINK_NODE
|
||||
void Lights::handleBattery(const HwLightState& state) {
|
||||
mBatteryState = state;
|
||||
setNotificationLED();
|
||||
}
|
||||
|
||||
void Lights::handleNotifications(const HwLightState& state) {
|
||||
mNotificationState = state;
|
||||
setNotificationLED();
|
||||
}
|
||||
|
||||
void Lights::handleAttention(const HwLightState& state) {
|
||||
mAttentionState = state;
|
||||
setNotificationLED();
|
||||
}
|
||||
|
||||
void Lights::setNotificationLED() {
|
||||
int32_t adjusted_brightness = MAX_INPUT_BRIGHTNESS;
|
||||
HwLightState state;
|
||||
#ifdef LED_BLN_NODE
|
||||
bool bln = false;
|
||||
#endif /* LED_BLN_NODE */
|
||||
|
||||
if (mNotificationState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_NOTIFICATION;
|
||||
state = mNotificationState;
|
||||
#ifdef LED_BLN_NODE
|
||||
bln = true;
|
||||
#endif /* LED_BLN_NODE */
|
||||
} else if (mAttentionState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_ATTENTION;
|
||||
state = mAttentionState;
|
||||
if (state.flashMode == FlashMode::HARDWARE) {
|
||||
if (state.flashOnMs > 0 && state.flashOffMs == 0) state.flashMode = FlashMode::NONE;
|
||||
state.color = 0x000000ff;
|
||||
}
|
||||
if (state.flashMode == FlashMode::NONE) {
|
||||
state.color = 0;
|
||||
}
|
||||
} else if (mBatteryState.color & COLOR_MASK) {
|
||||
adjusted_brightness = LED_BRIGHTNESS_BATTERY;
|
||||
state = mBatteryState;
|
||||
} else {
|
||||
set(LED_BLINK_NODE, "0x00000000 0 0");
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.flashMode == FlashMode::NONE) {
|
||||
state.flashOnMs = 0;
|
||||
state.flashOffMs = 0;
|
||||
}
|
||||
|
||||
state.color = calibrateColor(state.color & COLOR_MASK, adjusted_brightness);
|
||||
set(LED_BLINK_NODE, ::android::base::StringPrintf("0x%08x %d %d", state.color, state.flashOnMs,
|
||||
state.flashOffMs));
|
||||
|
||||
#ifdef LED_BLN_NODE
|
||||
if (bln) {
|
||||
set(LED_BLN_NODE, (state.color & COLOR_MASK) ? 1 : 0);
|
||||
}
|
||||
#endif /* LED_BLN_NODE */
|
||||
}
|
||||
|
||||
uint32_t Lights::calibrateColor(uint32_t color, int32_t brightness) {
|
||||
uint32_t red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R;
|
||||
uint32_t green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G;
|
||||
uint32_t blue = (color & 0xFF) * LED_ADJUSTMENT_B;
|
||||
|
||||
return (((red * brightness) / 255) << 16) + (((green * brightness) / 255) << 8) +
|
||||
((blue * brightness) / 255);
|
||||
}
|
||||
#endif /* LED_BLINK_NODE */
|
||||
|
||||
#define AutoHwLight(light) {.id = (int32_t)light, .type = light, .ordinal = 0}
|
||||
|
||||
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight> *_aidl_return) {
|
||||
for (auto const& light : mLights) {
|
||||
_aidl_return->push_back(AutoHwLight(light.first));
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
uint32_t Lights::rgbToBrightness(const HwLightState& state) {
|
||||
uint32_t color = state.color & COLOR_MASK;
|
||||
|
||||
return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) + (29 * (color & 0xff))) >>
|
||||
8;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
54
universal7885-common/aidl/light/Lights.h
Normal file
54
universal7885-common/aidl/light/Lights.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/light/BnLights.h>
|
||||
#include <unordered_map>
|
||||
#include "samsung_lights.h"
|
||||
|
||||
using ::aidl::android::hardware::light::HwLightState;
|
||||
using ::aidl::android::hardware::light::HwLight;
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class Lights : public BnLights {
|
||||
public:
|
||||
Lights();
|
||||
|
||||
ndk::ScopedAStatus setLightState(int32_t id, const HwLightState& state) override;
|
||||
ndk::ScopedAStatus getLights(std::vector<HwLight> *_aidl_return) override;
|
||||
|
||||
private:
|
||||
void handleBacklight(const HwLightState& state);
|
||||
#ifdef BUTTON_BRIGHTNESS_NODE
|
||||
void handleButtons(const HwLightState& state);
|
||||
#endif /* BUTTON_BRIGHTNESS_NODE */
|
||||
#ifdef LED_BLINK_NODE
|
||||
void handleBattery(const HwLightState& state);
|
||||
void handleNotifications(const HwLightState& state);
|
||||
void handleAttention(const HwLightState& state);
|
||||
void setNotificationLED();
|
||||
uint32_t calibrateColor(uint32_t color, int32_t brightness);
|
||||
|
||||
HwLightState mAttentionState;
|
||||
HwLightState mBatteryState;
|
||||
HwLightState mNotificationState;
|
||||
#endif /* LED_BLINK_NODE */
|
||||
|
||||
uint32_t rgbToBrightness(const HwLightState& state);
|
||||
|
||||
std::mutex mLock;
|
||||
std::unordered_map<LightType, std::function<void(const HwLightState&)>> mLights;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
service vendor.light-default /vendor/bin/hw/android.hardware.light-service.samsung
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
shutdown critical
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.light</name>
|
||||
<fqname>ILights/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
58
universal7885-common/aidl/light/include/samsung_lights.h
Normal file
58
universal7885-common/aidl/light/include/samsung_lights.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The CyanogenMod Project
|
||||
* Copyright (C) 2017 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef SAMSUNG_LIGHTS_H
|
||||
#define SAMSUNG_LIGHTS_H
|
||||
|
||||
/*
|
||||
* Board specific nodes
|
||||
*
|
||||
* If your kernel exposes these controls in another place, you can either
|
||||
* symlink to the locations given here, or override this header in your
|
||||
* device tree.
|
||||
*/
|
||||
#define PANEL_BRIGHTNESS_NODE "/sys/class/backlight/panel/brightness"
|
||||
#define PANEL_MAX_BRIGHTNESS_NODE "/sys/class/backlight/panel/max_brightness"
|
||||
#define BUTTON_BRIGHTNESS_NODE "/sys/class/sec/sec_touchkey/brightness"
|
||||
#define LED_BLINK_NODE "/sys/class/sec/led/led_blink"
|
||||
#define LED_BLN_NODE "/sys/class/misc/backlightnotification/notification_led"
|
||||
|
||||
// Uncomment to enable variable button brightness
|
||||
//#define VAR_BUTTON_BRIGHTNESS 1
|
||||
|
||||
/*
|
||||
* Brightness adjustment factors
|
||||
*
|
||||
* If one of your device's LEDs is more powerful than the others, use these
|
||||
* values to equalise them. This value is in the range 0.0-1.0.
|
||||
*/
|
||||
#define LED_ADJUSTMENT_R 1.0
|
||||
#define LED_ADJUSTMENT_G 1.0
|
||||
#define LED_ADJUSTMENT_B 1.0
|
||||
|
||||
/*
|
||||
* Light brightness factors
|
||||
*
|
||||
* It might make sense for all colours to be scaled down (for example, if your
|
||||
* LED is too bright). Use these values to adjust the brightness of each
|
||||
* light. This value is within the range 0-255.
|
||||
*/
|
||||
#define LED_BRIGHTNESS_BATTERY 255
|
||||
#define LED_BRIGHTNESS_NOTIFICATION 255
|
||||
#define LED_BRIGHTNESS_ATTENTION 255
|
||||
|
||||
#endif // SAMSUNG_LIGHTS_H
|
||||
27
universal7885-common/aidl/light/service.cpp
Normal file
27
universal7885-common/aidl/light/service.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.light-service.samsung"
|
||||
|
||||
#include "Lights.h"
|
||||
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
#include <android-base/logging.h>
|
||||
|
||||
using ::aidl::android::hardware::light::Lights;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Lights> lights = ndk::SharedRefBase::make<Lights>();
|
||||
|
||||
const std::string instance = std::string() + Lights::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(lights->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
Loading…
Reference in a new issue