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 <ralph950412@gmail.com>
Signed-off-by: Hexdare <mohammedasimuddin786@gmail.com>
This commit is contained in:
Dhina17 2025-02-06 03:00:25 +08:00 committed by DigiGoon
parent 3c102e80f4
commit acf4649586
6 changed files with 100 additions and 0 deletions

View file

@ -46,6 +46,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

22
camera/Android.bp Normal file
View file

@ -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"
],
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (C) 2024 LibreMobileOS Foundation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "CameraProviderExtension.h"
#include <fstream>
#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 <typename T>
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 <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;
}
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);
}

View file

@ -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

1
sepolicy/vendor/cameraserver.te vendored Normal file
View file

@ -0,0 +1 @@
allow cameraserver sysfs_leds:file rw_file_perms;

View file

@ -13,6 +13,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