forked from donjohanliebert/hardware_xiaomi
aidl: light: Rewrite backlight support
* This properly handles max brightness node Change-Id: I8afcf4bb7cef9c71d9a03bac7e118b8d9cb0565b
This commit is contained in:
parent
627e6ad184
commit
2686a6a730
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (C) 2021 The LineageOS Project
|
||||
// Copyright (C) 2021-2022 The LineageOS Project
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -10,6 +10,7 @@ cc_binary {
|
||||
init_rc: ["android.hardware.light-service.xiaomi.rc"],
|
||||
vintf_fragments: ["android.hardware.light-service.xiaomi.xml"],
|
||||
srcs: [
|
||||
"Backlight.cpp",
|
||||
"Lights.cpp",
|
||||
"LED.cpp",
|
||||
"Utils.cpp",
|
||||
|
85
aidl/light/Backlight.cpp
Normal file
85
aidl/light/Backlight.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Backlight.h"
|
||||
|
||||
#include "LED.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class BacklightBrightness : public BacklightDevice {
|
||||
public:
|
||||
BacklightBrightness(std::string name) : mBasePath(mkBacklightBasePath + name + "/") {
|
||||
if (!readFromFile(mBasePath + "max_brightness", &mMaxBrightness)) {
|
||||
mMaxBrightness = kDefaultMaxBrightness;
|
||||
}
|
||||
};
|
||||
|
||||
void setBacklight(uint8_t value) {
|
||||
writeToFile(mBasePath + "brightness", value * mMaxBrightness / 0xFF);
|
||||
}
|
||||
|
||||
bool exists() {
|
||||
return fileWriteable(mBasePath + "brightness");
|
||||
}
|
||||
private:
|
||||
std::string mBasePath;
|
||||
uint32_t mMaxBrightness;
|
||||
|
||||
inline static const std::string mkBacklightBasePath = "/sys/class/backlight/";
|
||||
inline static const uint32_t kDefaultMaxBrightness = 255;
|
||||
};
|
||||
|
||||
class LEDBacklight : public BacklightDevice {
|
||||
public:
|
||||
LEDBacklight(std::string type) : mLED(type) {};
|
||||
|
||||
void setBacklight(uint8_t value) {
|
||||
mLED.setBrightness(value);
|
||||
}
|
||||
|
||||
bool exists() {
|
||||
return mLED.exists();
|
||||
}
|
||||
private:
|
||||
LED mLED;
|
||||
};
|
||||
|
||||
static const std::string kBacklightDevices[] = {
|
||||
"panel0-backlight",
|
||||
};
|
||||
|
||||
static const std::string kLedDevices[] = {
|
||||
"lcd-backlight",
|
||||
};
|
||||
|
||||
BacklightDevice *getBacklightDevice() {
|
||||
for (auto &device : kBacklightDevices) {
|
||||
auto backlight = new BacklightBrightness(device);
|
||||
if (backlight->exists()) {
|
||||
return backlight;
|
||||
}
|
||||
delete backlight;
|
||||
}
|
||||
|
||||
for (auto& device : kLedDevices) {
|
||||
auto backlight = new LEDBacklight(device);
|
||||
if (backlight->exists()) {
|
||||
return backlight;
|
||||
}
|
||||
delete backlight;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
27
aidl/light/Backlight.h
Normal file
27
aidl/light/Backlight.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class BacklightDevice {
|
||||
public:
|
||||
virtual ~BacklightDevice() = default;
|
||||
|
||||
virtual void setBacklight(uint8_t value) = 0;
|
||||
virtual bool exists() = 0;
|
||||
};
|
||||
|
||||
BacklightDevice *getBacklightDevice();
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
@ -15,11 +15,6 @@ namespace android {
|
||||
namespace hardware {
|
||||
namespace light {
|
||||
|
||||
static const std::string kAllBacklightPaths[] = {
|
||||
"/sys/class/backlight/panel0-backlight/brightness",
|
||||
"/sys/class/leds/lcd-backlight/brightness",
|
||||
};
|
||||
|
||||
static const std::string kAllButtonsPaths[] = {
|
||||
"/sys/class/leds/button-backlight/brightness",
|
||||
"/sys/class/leds/button-backlight1/brightness",
|
||||
@ -48,13 +43,9 @@ static const HwLight kButtonsHwLight = AutoHwLight(LightType::BUTTONS);
|
||||
static const HwLight kNotificationHwLight = AutoHwLight(LightType::NOTIFICATIONS);
|
||||
|
||||
Lights::Lights() {
|
||||
for (auto& backlight : kAllBacklightPaths) {
|
||||
if (!fileWriteable(backlight))
|
||||
continue;
|
||||
|
||||
mBacklightPath = backlight;
|
||||
mBacklightDevice = getBacklightDevice();
|
||||
if (mBacklightDevice) {
|
||||
mLights.push_back(kBacklightHwLight);
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto& buttons : kAllButtonsPaths) {
|
||||
@ -80,8 +71,8 @@ ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state)
|
||||
LightType type = static_cast<LightType>(id);
|
||||
switch (type) {
|
||||
case LightType::BACKLIGHT:
|
||||
if (!mBacklightPath.empty())
|
||||
writeToFile(mBacklightPath, color.toBrightness());
|
||||
if (mBacklightDevice)
|
||||
mBacklightDevice->setBacklight(color.toBrightness());
|
||||
break;
|
||||
case LightType::BUTTONS:
|
||||
for (auto& buttons : mButtonsPaths)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The LineageOS Project
|
||||
* Copyright (C) 2021-2022 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
#include <aidl/android/hardware/light/BnLights.h>
|
||||
#include <mutex>
|
||||
#include "Backlight.h"
|
||||
|
||||
using ::aidl::android::hardware::light::HwLightState;
|
||||
using ::aidl::android::hardware::light::HwLight;
|
||||
@ -28,7 +29,7 @@ private:
|
||||
|
||||
std::vector<HwLight> mLights;
|
||||
|
||||
std::string mBacklightPath;
|
||||
BacklightDevice *mBacklightDevice;
|
||||
std::vector<std::string> mButtonsPaths;
|
||||
bool mWhiteLED;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
on early-boot
|
||||
# Notification LEDs
|
||||
chown system system /sys/class/leds/red/blink
|
||||
chown system system /sys/class/leds/red/breath
|
||||
chown system system /sys/class/leds/red/brightness
|
||||
@ -19,9 +20,14 @@ on early-boot
|
||||
chown system system /sys/class/leds/white/brightness
|
||||
chown system system /sys/class/leds/white/max_brightness
|
||||
|
||||
chown system system /sys/class/leds/lcd-backlight/brightness
|
||||
# Backlight
|
||||
chown system system /sys/class/backlight/panel0-backlight/brightness
|
||||
chown system system /sys/class/backlight/panel0-backlight/max_brightness
|
||||
|
||||
chown system system /sys/class/leds/lcd-backlight/brightness
|
||||
chown system system /sys/class/leds/lcd-backlight/max_brightness
|
||||
|
||||
# Buttons
|
||||
chown system system /sys/class/leds/button-backlight/brightness
|
||||
chown system system /sys/class/leds/button-backlight1/brightness
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user