mirror of
https://github.com/Evolution-X-Devices/device_xiaomi_sm6150-common
synced 2026-01-27 12:07:36 +00:00
sm6150-common: Implement torch light control
[RealJohnGalt:] modify for oneplus usage, add toggle switch [cyberknight777]: Adapt nodes and SEPolicy for sunny Change-Id: I8ff5d814-d58d-4ed1-9b42-b025415a5c85 Signed-off-by: Dhina17 <dhinalogu@gmail.com> Signed-off-by: therealmharc <therealmharc@gmail.com>
This commit is contained in:
@@ -51,6 +51,7 @@ MALLOC_SVELTE := true
|
||||
MALLOC_SVELTE_FOR_LIBC32 := true
|
||||
TARGET_CAMERA_OVERRIDE_FORMAT_FROM_RESERVED := true
|
||||
TARGET_CAMERA_PACKAGE_NAME := com.android.camera
|
||||
TARGET_CAMERA_SERVICE_EXT_LIB := //$(COMMON_PATH):libcameraservice_extension.sm6150
|
||||
|
||||
# Filesystem
|
||||
TARGET_FS_CONFIG_GEN := $(COMMON_PATH)/configs/config.fs
|
||||
|
||||
22
camera/Android.bp
Normal file
22
camera/Android.bp
Normal 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.sm6150",
|
||||
srcs: ["CameraProviderExtension.cpp"],
|
||||
include_dirs: [
|
||||
"frameworks/av/services/camera/libcameraservice/common"
|
||||
],
|
||||
}
|
||||
71
camera/CameraProviderExtension.cpp
Normal file
71
camera/CameraProviderExtension.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:switch_2/brightness"
|
||||
|
||||
static std::string kTorchLedPaths[] = {
|
||||
"/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_0",
|
||||
"/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/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 = kTorchLedPaths[0] + "/" + TORCH_MAX_BRIGHTNESS;
|
||||
return get(node, 0);
|
||||
}
|
||||
|
||||
int32_t getTorchStrengthLevelExt() {
|
||||
// We write same value in the both LEDs,
|
||||
// so get from one.
|
||||
auto node = kTorchLedPaths[0] + "/" + TORCH_BRIGHTNESS;
|
||||
return get(node, 0);
|
||||
}
|
||||
|
||||
void setTorchStrengthLevelExt(int32_t torchStrength) {
|
||||
set(TOGGLE_SWITCH, 0);
|
||||
for (auto& path : kTorchLedPaths) {
|
||||
auto node = path + "/" + TORCH_BRIGHTNESS;
|
||||
set(node, torchStrength);
|
||||
}
|
||||
if (torchStrength > 0)
|
||||
set(TOGGLE_SWITCH, 255);
|
||||
}
|
||||
@@ -185,3 +185,8 @@ firmware_directories /vendor/firmware_mnt/image/
|
||||
|
||||
# Charger
|
||||
/sys/class/power_supply/battery input_suspend 0660 system system
|
||||
|
||||
# Torch control
|
||||
/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:switch_2 brightness 0660 cameraserver camera
|
||||
/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_0 brightness 0660 cameraserver camera
|
||||
/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_1 brightness 0660 cameraserver camera
|
||||
|
||||
1
sepolicy/vendor/cameraserver.te
vendored
1
sepolicy/vendor/cameraserver.te
vendored
@@ -1 +1,2 @@
|
||||
hal_client_domain(cameraserver, hal_motor)
|
||||
allow cameraserver sysfs_torch:file rw_file_perms;
|
||||
|
||||
3
sepolicy/vendor/file.te
vendored
3
sepolicy/vendor/file.te
vendored
@@ -1,5 +1,8 @@
|
||||
# Data files
|
||||
type per_boot_file, file_type, data_file_type, core_data_file_type;
|
||||
|
||||
# Torch
|
||||
type sysfs_torch, fs_type, sysfs_type;
|
||||
|
||||
# Touchpanel
|
||||
type sysfs_touchpanel, fs_type, sysfs_type;
|
||||
|
||||
10
sepolicy/vendor/genfs_contexts
vendored
10
sepolicy/vendor/genfs_contexts
vendored
@@ -72,5 +72,15 @@ genfscon sysfs /devices/platform/soc/soc:maxim_ds28e16/power_supply/batt_verify/
|
||||
genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc/wakeup u:object_r:sysfs_wakeup:s0
|
||||
genfscon sysfs /devices/virtual/input/input1/wakeup u:object_r:sysfs_wakeup:s0
|
||||
|
||||
# Torch
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/flashlight/brightness u:object_r:sysfs_leds:s0
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_0/brightness u:object_r:sysfs_torch:s0
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_0/max_brightness u:object_r:sysfs_torch:s0
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_1/brightness u:object_r:sysfs_torch:s0
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_1/max_brightness u:object_r:sysfs_torch:s0
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:switch_0/brightness u:object_r:sysfs_leds:s0
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:switch_1/brightness u:object_r:sysfs_leds:s0
|
||||
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:switch_2/brightness u:object_r:sysfs_torch:s0
|
||||
|
||||
# Touchpanel
|
||||
genfscon sysfs /devices/virtual/touch/touch_dev/ u:object_r:sysfs_touchpanel:s0
|
||||
|
||||
Reference in New Issue
Block a user