sdm660-common: Introduce kernelspace battery saver

* Needs Kernel side support
 * This activates kernelspace battery saver via powerhal whenever
   battery saver is enabled in userspace, thereby lowering power
   consumption at kernel-level by disabling boosts and such

Signed-off-by: clarencelol <clarencekuiek@icloud.com>
Change-Id: I2623503db27d7518de519bcaa3f5af6ab83879d0
This commit is contained in:
ghostrider-reborn 2021-07-25 13:25:15 +08:00 committed by pix106
parent efd182dee0
commit 79c64bc007
6 changed files with 69 additions and 0 deletions

View file

@ -79,6 +79,9 @@ BOARD_SUPPORTS_SOUND_TRIGGER := true
USE_CUSTOM_AUDIO_POLICY := 1
USE_XML_AUDIO_POLICY_CONF := 1
# Battery Saver
TARGET_POWERHAL_MODE_EXT := $(COMMON_PATH)/power-libperfmgr/power/power-mode.cpp
# Bluetooth
BOARD_HAVE_BLUETOOTH := true
BOARD_HAVE_BLUETOOTH_QCOM := true

View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 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.
*/
#include <aidl/android/hardware/power/BnPower.h>
#include <android-base/file.h>
#include "power-common.h"
#define BATTERY_SAVER_NODE "/sys/module/battery_saver/parameters/enabled"
namespace aidl {
namespace android {
namespace hardware {
namespace power {
namespace impl {
using ::aidl::android::hardware::power::Mode;
bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
switch (type) {
case Mode::LOW_POWER:
*_aidl_return = true;
return true;
default:
return false;
}
}
bool setDeviceSpecificMode(Mode type, bool enabled) {
switch (type) {
case Mode::LOW_POWER:
::android::base::WriteStringToFile(enabled ? "Y" : "N", BATTERY_SAVER_NODE, true);
return true;
default:
return false;
}
}
} // namespace impl
} // namespace power
} // namespace hardware
} // namespace android
} // namespace aidl

View file

@ -75,6 +75,9 @@ on init
chmod 0664 /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq
chmod 0664 /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq
chown system system /sys/module/battery_saver/parameters/enabled
chmod 0664 /sys/module/battery_saver/parameters/enabled
on fs
wait /dev/block/platform/soc/${ro.boot.bootdevice}
symlink /dev/block/platform/soc/${ro.boot.bootdevice} /dev/block/bootdevice

View file

@ -18,3 +18,6 @@ type kcal_dev, sysfs_type, fs_type;
# Sockets
type audio_socket, file_type;
# Battery Saver
type sysfs_battery_saver, fs_type, sysfs_type;

View file

@ -2,6 +2,9 @@
genfscon sysfs /devices/platform/soc/c175000.i2c/i2c-1/1-0062 u:object_r:sysfs_battery_supply:s0
genfscon sysfs /devices/platform/soc/c176000.i2c/i2c-2/2-001d u:object_r:sysfs_battery_supply:s0
# Battery Saver
genfscon sysfs /module/battery_saver/parameters/enabled u:object_r:sysfs_battery_saver:s0
# Camera
genfscon sysfs /devices/platform/soc/ca0c000.qcom,cci/ca0c000.qcom,cci:qcom,camera@0/video4linux/video2/name u:object_r:sysfs_graphics:s0
genfscon sysfs /devices/platform/soc/ca0c000.qcom,cci/ca0c000.qcom,cci:qcom,camera@1/video4linux/video3/name u:object_r:sysfs_graphics:s0

View file

@ -1,5 +1,7 @@
allow hal_power_default cgroup:file read;
allow hal_power_default device_latency:chr_file rw_file_perms;
allow hal_power_default sysfs_battery_saver:dir r_dir_perms;
allow hal_power_default sysfs_battery_saver:file rw_file_perms;
allow hal_power_default { sysfs_devfreq sysfs_kgsl }:dir search;
allow hal_power_default { sysfs_devfreq sysfs_kgsl }:{ file lnk_file } rw_file_perms;
allow hal_power_default sysfs_devices_system_cpu:file rw_file_perms;