diff --git a/lights/Android.bp b/lights/Android.bp deleted file mode 100644 index 155b9db..0000000 --- a/lights/Android.bp +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (C) 2019-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. -// 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. - -cc_binary { - name: "android.hardware.lights-service.motolahaina", - relative_install_path: "hw", - init_rc: ["android.hardware.lights.motolahaina.rc"], - vintf_fragments: ["android.hardware.lights.motolahaina.xml"], - vendor: true, - shared_libs: [ - "libbase", - "liblog", - "libhardware", - "libbinder_ndk", - "android.hardware.light-V1-ndk", - ], - srcs: [ - "Lights.cpp", - "main.cpp", - ], -} diff --git a/lights/Lights.cpp b/lights/Lights.cpp deleted file mode 100644 index 1ce20cf..0000000 --- a/lights/Lights.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * Copyright (C) 2020-2022 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. - */ - -#define LOG_TAG "android.hardware.lights-service.motolahaina" - -#include "Lights.h" -#include -#include - -/* clang-format off */ -#define PPCAT_NX(A, B) A/B -#define PPCAT(A, B) PPCAT_NX(A, B) -#define STRINGIFY_INNER(x) #x -#define STRINGIFY(x) STRINGIFY_INNER(x) - -#define CHARGING_ATTR(x) STRINGIFY(PPCAT(/sys/class/leds/charging, x)) -/* clang-format on */ - -namespace aidl { -namespace android { -namespace hardware { -namespace light { - -namespace { - -// Write value to path and close file. -template -inline bool WriteToFile(const std::string& path, T content) { - return ::android::base::WriteStringToFile(std::to_string(content), path); -} - -uint32_t 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 && alpha != 0) { - red = red * alpha / 0xFF; - green = green * alpha / 0xFF; - blue = blue * alpha / 0xFF; - } - - return (77 * red + 150 * green + 29 * blue) >> 8; -} - -inline bool IsLit(uint32_t color) { - return color & 0x00ffffff; -} - -void ApplyNotificationState(const HwLightState& state) { - bool blink = state.flashOnMs > 0 && state.flashOffMs > 0; - bool ok = false; - - switch (state.flashMode) { - case FlashMode::HARDWARE: - ok = WriteToFile(CHARGING_ATTR(breath), blink); - // fallback to timed blinking if breath is not supported - if (ok) break; - FALLTHROUGH_INTENDED; - case FlashMode::TIMED: - ok = WriteToFile(CHARGING_ATTR(delay_off), state.flashOffMs); - ok &= WriteToFile(CHARGING_ATTR(delay_on), state.flashOnMs); - // fallback to constant on if timed blinking is not supported - if (ok) break; - FALLTHROUGH_INTENDED; - case FlashMode::NONE: - default: - ok = WriteToFile(CHARGING_ATTR(brightness), RgbaToBrightness(state.color)); - break; - } - - LOG(DEBUG) << __func__ << ": mode=" << toString(state.flashMode) << ", colorRGB=" << std::hex - << state.color << std::dec << ", onMS=" << state.flashOnMs - << ", offMS=" << state.flashOffMs << ", ok=" << ok; -} - -} // anonymous namespace - -ndk::ScopedAStatus Lights::setLightState(int id, const HwLightState& state) { - static_assert(kAvailableLights.size() == std::tuple_size_v); - - if (id == static_cast(LightType::BACKLIGHT)) { - // Stub backlight handling - return ndk::ScopedAStatus::ok(); - } - - // Update saved state first - bool found = false; - for (size_t i = 0; i < notif_states_.size(); ++i) { - if (kAvailableLights[i].id == id) { - notif_states_[i] = state; - LOG(DEBUG) << __func__ << ": updating id=" << id - << ", type=" << toString(kAvailableLights[i].type); - found = true; - break; - } - } - if (!found) { - LOG(ERROR) << "Light not supported"; - return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); - } - - // Lit up in order or fallback to battery light if others are dim - for (size_t i = 0; i < notif_states_.size(); ++i) { - auto&& cur_state = notif_states_[i]; - auto&& cur_light = kAvailableLights[i]; - if (IsLit(cur_state.color) || cur_light.type == LightType::BATTERY) { - LOG(DEBUG) << __func__ << ": applying id=" << cur_light.id - << ", type=" << toString(cur_light.type); - ApplyNotificationState(cur_state); - break; - } - } - - return ndk::ScopedAStatus::ok(); -} - -ndk::ScopedAStatus Lights::getLights(std::vector* lights) { - lights->insert(lights->end(), kAvailableLights.begin(), kAvailableLights.end()); - // We don't handle backlight but still need to report as supported. - lights->push_back({static_cast(LightType::BACKLIGHT), 0, LightType::BACKLIGHT}); - return ndk::ScopedAStatus::ok(); -} - -} // namespace light -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/lights/Lights.h b/lights/Lights.h deleted file mode 100644 index 323b878..0000000 --- a/lights/Lights.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * Copyright (C) 2020-2022 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. - */ - -#pragma once - -#include -#include - -namespace aidl { -namespace android { -namespace hardware { -namespace light { - -// Keep sorted in the order of priority. -constexpr std::array kAvailableLights = { - // id, ordinal, type - HwLight{static_cast(LightType::NOTIFICATIONS), 0, LightType::NOTIFICATIONS}, - HwLight{static_cast(LightType::BATTERY), 0, LightType::BATTERY}, -}; - -class Lights : public BnLights { - public: - ndk::ScopedAStatus setLightState(int id, const HwLightState& state) override; - ndk::ScopedAStatus getLights(std::vector* types) override; - - private: - std::array notif_states_; -}; - -} // namespace light -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/lights/android.hardware.lights.motolahaina.rc b/lights/android.hardware.lights.motolahaina.rc deleted file mode 100644 index 8760130..0000000 --- a/lights/android.hardware.lights.motolahaina.rc +++ /dev/null @@ -1,11 +0,0 @@ -service vendor.light /vendor/bin/hw/android.hardware.lights-service.motolahaina - class hal - user system - group system - shutdown critical - -on boot - chown system system /sys/class/leds/charging/breath - chown system system /sys/class/leds/charging/brightness - chown system system /sys/class/leds/charging/delay_off - chown system system /sys/class/leds/charging/delay_on diff --git a/lights/android.hardware.lights.motolahaina.xml b/lights/android.hardware.lights.motolahaina.xml deleted file mode 100644 index db604d6..0000000 --- a/lights/android.hardware.lights.motolahaina.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 8509bfb..0000000 --- a/lights/main.cpp +++ /dev/null @@ -1,37 +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 -#include -#include -#include "Lights.h" - -using ::aidl::android::hardware::light::Lights; - -int main() { - ABinderProcess_setThreadPoolMaxThreadCount(0); - std::shared_ptr lights = ndk::SharedRefBase::make(); - if (!lights) { - return EXIT_FAILURE; - } - - 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/rootdir/etc/init/hw/init.mmi.rc b/rootdir/etc/init/hw/init.mmi.rc index a274f9e..402c8eb 100644 --- a/rootdir/etc/init/hw/init.mmi.rc +++ b/rootdir/etc/init/hw/init.mmi.rc @@ -272,12 +272,6 @@ on boot # Change ownership and permission for leds backlight chmod 0664 /sys/class/leds/lcd-backlight/brightness - chown system system /sys/class/leds/charging/brightness - chmod 0664 /sys/class/leds/charging/brightness - - # change permission of red leds - chown system system /sys/class/leds/red/brightness - chmod 0664 /sys/class/leds/red/brightness # Change ownership and permission for vibrator chown system system /sys/class/timed_output/vibrator/enable diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 0cebdb6..bb5aa29 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -56,9 +56,6 @@ # IFAA /(vendor|system/vendor)/bin/hw/vendor\.zui\.hardware\.ifaa@1\.0-service u:object_r:hal_ifaa_default_exec:s0 -# Lights -/(vendor|system/vendor)/bin/hw/android\.hardware\.lights-service\.motolahaina u:object_r:hal_light_default_exec:s0 - # LiveDisplay /(vendor|system/vendor)/bin/hw/vendor\.lineage\.livedisplay@2\.1-service\.motorola_lahaina u:object_r:hal_lineage_livedisplay_qti_exec:s0 diff --git a/sm7325.mk b/sm7325.mk index 2ac2ccb..c7fdb12 100644 --- a/sm7325.mk +++ b/sm7325.mk @@ -254,10 +254,6 @@ PRODUCT_COPY_FILES += \ PRODUCT_PACKAGES += \ android.hardware.keymaster@4.1.vendor -# Lights -PRODUCT_PACKAGES += \ - android.hardware.lights-service.motolahaina - # LiveDisplay PRODUCT_PACKAGES += \ vendor.lineage.livedisplay@2.1-service.motorola_lahaina