From d01e67eab5db6b5ec210e31200e7bc67fd223a7d Mon Sep 17 00:00:00 2001 From: Dhina17 Date: Thu, 6 Feb 2025 03:00:25 +0800 Subject: [PATCH] sm8350-common: Implement torch light control [RealJohnGalt: Modify for oneplus usage and add toggle switch] [cyberknight777/ralph950412: Adapt nodes and SEPolicy for Xiaomi SM8350] [Hexdare: Adapt nodes and SEPolicy for Haydn] Change-Id: Icd32d1f6aedb55462c9df4d7cc63a2a4c4e4263e Signed-off-by: ralph950412 Signed-off-by: Hexdare --- BoardConfigCommon.mk | 3 ++ camera/Android.bp | 22 ++++++++++ camera/CameraProviderExtension.cpp | 65 ++++++++++++++++++++++++++++++ rootdir/etc/ueventd.rc | 4 ++ sepolicy/vendor/cameraserver.te | 1 + sepolicy/vendor/genfs_contexts | 5 +++ 6 files changed, 100 insertions(+) create mode 100644 camera/Android.bp create mode 100644 camera/CameraProviderExtension.cpp create mode 100644 sepolicy/vendor/cameraserver.te diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index d937b68..24db12d 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -48,6 +48,9 @@ TARGET_NO_BOOTLOADER := true # Display TARGET_SCREEN_DENSITY ?= 440 +# Camera +TARGET_CAMERA_SERVICE_EXT_LIB := //$(COMMON_PATH):libcameraservice_extension.xiaomi_sm8350 + # Filesystem TARGET_FS_CONFIG_GEN := $(COMMON_PATH)/config.fs diff --git a/camera/Android.bp b/camera/Android.bp new file mode 100644 index 0000000..8c7a2a2 --- /dev/null +++ b/camera/Android.bp @@ -0,0 +1,22 @@ +// +// Copyright (C) 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. + +cc_library_static { + name: "libcameraservice_extension.xiaomi_sm8350", + srcs: ["CameraProviderExtension.cpp"], + include_dirs: [ + "frameworks/av/services/camera/libcameraservice/common" + ], +} diff --git a/camera/CameraProviderExtension.cpp b/camera/CameraProviderExtension.cpp new file mode 100644 index 0000000..e008e15 --- /dev/null +++ b/camera/CameraProviderExtension.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024 LibreMobileOS Foundation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "CameraProviderExtension.h" + +#include + +#define TORCH_BRIGHTNESS "brightness" +#define TORCH_MAX_BRIGHTNESS "max_brightness" +#define TOGGLE_SWITCH "/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:switch_1/brightness" +static std::string kTorchLedPath = "/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_1"; + +/** + * Write value to path and close file. + */ +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + file << value; +} + +/** + * Read value from the path and close file. + */ +template +static T get(const std::string& path, const T& def) { + std::ifstream file(path); + T result; + + file >> result; + return file.fail() ? def : result; +} + +bool supportsTorchStrengthControlExt() { + return true; +} + +int32_t getTorchDefaultStrengthLevelExt() { + return 7; +} + +int32_t getTorchMaxStrengthLevelExt() { + // In our device, both LEDs has same maximum value + // so get from one. + auto node = kTorchLedPath + "/" + TORCH_MAX_BRIGHTNESS; + return get(node, 0); +} + +int32_t getTorchStrengthLevelExt() { + // We write same value in the both LEDs, + // so get from one. + auto node = kTorchLedPath + "/" + TORCH_BRIGHTNESS; + return get(node, 0); +} + +void setTorchStrengthLevelExt(int32_t torchStrength) { + set(TOGGLE_SWITCH, 0); + auto node = kTorchLedPath + "/" + TORCH_BRIGHTNESS; + set(node, torchStrength); + if (torchStrength > 0) + set(TOGGLE_SWITCH, 255); +} diff --git a/rootdir/etc/ueventd.rc b/rootdir/etc/ueventd.rc index 5aa9b35..9abf5d6 100644 --- a/rootdir/etc/ueventd.rc +++ b/rootdir/etc/ueventd.rc @@ -146,3 +146,7 @@ firmware_directories /vendor/firmware_mnt/image/ # Battery /sys/class/qcom-battery reverse_chg_mode 0644 system system + +# Torch control +/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_1 brightness 0660 cameraserver camera +/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:switch_1 0660 cameraserver camera diff --git a/sepolicy/vendor/cameraserver.te b/sepolicy/vendor/cameraserver.te new file mode 100644 index 0000000..4f05e2e --- /dev/null +++ b/sepolicy/vendor/cameraserver.te @@ -0,0 +1 @@ +allow cameraserver sysfs_leds:file rw_file_perms; diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts index 5d06459..755a7b9 100644 --- a/sepolicy/vendor/genfs_contexts +++ b/sepolicy/vendor/genfs_contexts @@ -7,6 +7,11 @@ genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc # USB genfscon sysfs /devices/platform/soc/soc:qcom,pmic_glink/soc:qcom,pmic_glink:qcom,ucsi/typec u:object_r:vendor_sysfs_usb_c:s0 +# Torch control +genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_1/brightness u:object_r:sysfs_leds:s0 +genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_1/max_brightness u:object_r:sysfs_leds:s0 +genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:switch_1/brightness u:object_r:sysfs_leds:s0 + # Wakeup nodes genfscon sysfs /devices/platform/goodix_ts.0/wakeup u:object_r:sysfs_wakeup:s0 genfscon sysfs /devices/platform/soc/17300000.qcom,lpass/subsys6/wakeup u:object_r:sysfs_wakeup:s0