From ede9a7fff19f538bdbe443fe0ee1c7b5f54011e8 Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Thu, 23 Sep 2021 16:00:04 +0200 Subject: [PATCH] sm7250-common: Move to common Xiaomi light AIDL Change-Id: I1edcfafce4ea7a76327f8466f8535e63cfc8ed39 --- lights/Android.bp | 16 --- lights/Lights.cpp | 182 ---------------------------------- lights/Lights.h | 59 ----------- lights/lights-xiaomi_lito.rc | 17 ---- lights/lights-xiaomi_lito.xml | 6 -- lights/main.cpp | 35 ------- lito.mk | 2 +- sepolicy/vendor/file_contexts | 2 +- 8 files changed, 2 insertions(+), 317 deletions(-) delete mode 100644 lights/Android.bp delete mode 100644 lights/Lights.cpp delete mode 100644 lights/Lights.h delete mode 100644 lights/lights-xiaomi_lito.rc delete mode 100644 lights/lights-xiaomi_lito.xml delete mode 100644 lights/main.cpp diff --git a/lights/Android.bp b/lights/Android.bp deleted file mode 100644 index 24d2e8d..0000000 --- a/lights/Android.bp +++ /dev/null @@ -1,16 +0,0 @@ -cc_binary { - name: "android.hardware.lights-service.xiaomi_lito", - relative_install_path: "hw", - init_rc: ["lights-xiaomi_lito.rc"], - vintf_fragments: ["lights-xiaomi_lito.xml"], - vendor: true, - shared_libs: [ - "libbase", - "libbinder_ndk", - "android.hardware.light-ndk_platform", - ], - srcs: [ - "Lights.cpp", - "main.cpp", - ], -} diff --git a/lights/Lights.cpp b/lights/Lights.cpp deleted file mode 100644 index 40432f7..0000000 --- a/lights/Lights.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source 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. - */ - -#include "Lights.h" - -#include -#include -#include - -using ::android::base::WriteStringToFile; - -namespace aidl { -namespace android { -namespace hardware { -namespace light { - -#define LED_PATH(led) "/sys/class/leds/" led "/" - -static const std::string led_paths[] { - [RED] = LED_PATH("red"), - [GREEN] = LED_PATH("green"), - [BLUE] = LED_PATH("blue"), - [WHITE] = LED_PATH("white"), -}; - -static const std::string kLCDFile = "/sys/class/backlight/panel0-backlight/brightness"; - -#define AutoHwLight(light) {.id = (int)light, .type = light, .ordinal = 0} - -// List of supported lights -const static std::vector kAvailableLights = { - AutoHwLight(LightType::BACKLIGHT), - AutoHwLight(LightType::BATTERY), - AutoHwLight(LightType::NOTIFICATIONS) -}; - -Lights::Lights() { - mWhiteLed = !access((led_paths[WHITE] + "brightness").c_str(), W_OK); -} - -// AIDL methods -ndk::ScopedAStatus Lights::setLightState(int id, const HwLightState& state) { - switch (id) { - case (int)LightType::BACKLIGHT: - WriteToFile(kLCDFile, RgbaToBrightness(state.color)); - break; - case (int)LightType::BATTERY: - mBattery = state; - handleSpeakerBatteryLocked(); - break; - case (int)LightType::NOTIFICATIONS: - mNotification = state; - handleSpeakerBatteryLocked(); - break; - default: - return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); - break; - } - - return ndk::ScopedAStatus::ok(); -} - -ndk::ScopedAStatus Lights::getLights(std::vector* lights) { - for (auto i = kAvailableLights.begin(); i != kAvailableLights.end(); i++) { - lights->push_back(*i); - } - return ndk::ScopedAStatus::ok(); -} - -// device methods -void Lights::setSpeakerLightLocked(const HwLightState& state) { - uint32_t alpha, red, green, blue; - uint32_t blink; - bool rc = true; - - // Extract brightness from AARRGGBB - alpha = (state.color >> 24) & 0xFF; - red = (state.color >> 16) & 0xFF; - green = (state.color >> 8) & 0xFF; - blue = state.color & 0xFF; - - // Scale RGB brightness if Alpha brightness is not 0xFF - if (alpha != 0xFF) { - red = (red * alpha) / 0xFF; - green = (green * alpha) / 0xFF; - blue = (blue * alpha) / 0xFF; - } - - blink = (state.flashOnMs != 0 && state.flashOffMs != 0); - - switch (state.flashMode) { - case FlashMode::HARDWARE: - case FlashMode::TIMED: - if (mWhiteLed) { - rc = setLedBreath(WHITE, blink); - } else { - if (!!red) - rc = setLedBreath(RED, blink); - if (!!green) - rc &= setLedBreath(GREEN, blink); - if (!!blue) - rc &= setLedBreath(BLUE, blink); - } - if (rc) - break; - FALLTHROUGH_INTENDED; - case FlashMode::NONE: - default: - if (mWhiteLed) { - rc = setLedBrightness(WHITE, RgbaToBrightness(state.color)); - } else { - rc = setLedBrightness(RED, red); - rc &= setLedBrightness(GREEN, green); - rc &= setLedBrightness(BLUE, blue); - } - break; - } - - return; -} - -void Lights::handleSpeakerBatteryLocked() { - if (IsLit(mBattery.color)) - return setSpeakerLightLocked(mBattery); - else - return setSpeakerLightLocked(mNotification); -} - -bool Lights::setLedBreath(led_type led, uint32_t value) { - return WriteToFile(led_paths[led] + "breath", value); -} - -bool Lights::setLedBrightness(led_type led, uint32_t value) { - return WriteToFile(led_paths[led] + "brightness", value); -} - -// Utils -bool Lights::IsLit(uint32_t color) { - return color & 0x00ffffff; -} - -uint32_t Lights::RgbaToBrightness(uint32_t color) { - // Extract brightness from AARRGGBB. - uint32_t alpha = (color >> 24) & 0xFF; - - // Retrieve each of the RGB colors - uint32_t red = (color >> 16) & 0xFF; - uint32_t green = (color >> 8) & 0xFF; - uint32_t blue = color & 0xFF; - - // Scale RGB colors if a brightness has been applied by the user - if (alpha != 0xFF) { - red = red * alpha / 0xFF; - green = green * alpha / 0xFF; - blue = blue * alpha / 0xFF; - } - - return (77 * red + 150 * green + 29 * blue) >> 8; -} - -// Write value to path and close file. -bool Lights::WriteToFile(const std::string& path, uint32_t content) { - return WriteStringToFile(std::to_string(content), path); -} - -} // namespace light -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/lights/Lights.h b/lights/Lights.h deleted file mode 100644 index 4be3577..0000000 --- a/lights/Lights.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source 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. - */ - -#pragma once - -#include - -namespace aidl { -namespace android { -namespace hardware { -namespace light { - -enum led_type { - RED, - GREEN, - BLUE, - WHITE, -}; - -class Lights : public BnLights { -public: - Lights(); - - ndk::ScopedAStatus setLightState(int id, const HwLightState& state) override; - ndk::ScopedAStatus getLights(std::vector* types) override; - -private: - void setSpeakerLightLocked(const HwLightState& state); - void handleSpeakerBatteryLocked(); - - bool setLedBreath(led_type led, uint32_t value); - bool setLedBrightness(led_type led, uint32_t value); - - bool IsLit(uint32_t color); - uint32_t RgbaToBrightness(uint32_t color); - bool WriteToFile(const std::string& path, uint32_t content); - - bool mWhiteLed; - HwLightState mNotification; - HwLightState mBattery; -}; - -} // namespace light -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/lights/lights-xiaomi_lito.rc b/lights/lights-xiaomi_lito.rc deleted file mode 100644 index 358845c..0000000 --- a/lights/lights-xiaomi_lito.rc +++ /dev/null @@ -1,17 +0,0 @@ -on early-boot - chown system system /sys/class/leds/red/breath - - chown system system /sys/class/leds/green/breath - - chown system system /sys/class/leds/blue/breath - - chown system system /sys/class/leds/white/breath - chown system system /sys/class/leds/white/brightness - - chown system system /sys/class/backlight/panel0-backlight/brightness - -service vendor.light-xiaomi_lito /vendor/bin/hw/android.hardware.lights-service.xiaomi_lito - class hal - user system - group system - shutdown critical \ No newline at end of file diff --git a/lights/lights-xiaomi_lito.xml b/lights/lights-xiaomi_lito.xml deleted file mode 100644 index db604d6..0000000 --- a/lights/lights-xiaomi_lito.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - android.hardware.light - ILights/default - - diff --git a/lights/main.cpp b/lights/main.cpp deleted file mode 100644 index a860bf4..0000000 --- a/lights/main.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source 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. - */ - -#include "Lights.h" - -#include -#include -#include - -using ::aidl::android::hardware::light::Lights; - -int main() { - ABinderProcess_setThreadPoolMaxThreadCount(0); - std::shared_ptr lights = ndk::SharedRefBase::make(); - - 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 reached -} diff --git a/lito.mk b/lito.mk index 9ade92a..02ee06d 100644 --- a/lito.mk +++ b/lito.mk @@ -256,7 +256,7 @@ PRODUCT_PACKAGES += \ # Lights PRODUCT_PACKAGES += \ - android.hardware.lights-service.xiaomi_lito + android.hardware.light-service.xiaomi # LiveDisplay PRODUCT_PACKAGES += \ diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index a81c883..e050d41 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -57,7 +57,7 @@ /sys/devices/platform/soc/[a-z0-9]+.i2c/i2c-[0-9]/[0-9]-[0-9]+/leds(/.*)? u:object_r:sysfs_leds:s0 # Lights -/vendor/bin/hw/android\.hardware\.lights-service\.xiaomi_lito u:object_r:hal_light_default_exec:s0 +/vendor/bin/hw/android\.hardware\.light-service\.xiaomi u:object_r:hal_light_default_exec:s0 # Mlipay /vendor/bin/mlipayd@1\.1 u:object_r:hal_mlipay_default_exec:s0