diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 474e3b3b..37cc5b70 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -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 diff --git a/power-libperfmgr/power/power-mode.cpp b/power-libperfmgr/power/power-mode.cpp new file mode 100644 index 00000000..1fee8ef6 --- /dev/null +++ b/power-libperfmgr/power/power-mode.cpp @@ -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 +#include +#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 diff --git a/rootdir/etc/init.target.rc b/rootdir/etc/init.target.rc index 63b6687d..a12c3997 100755 --- a/rootdir/etc/init.target.rc +++ b/rootdir/etc/init.target.rc @@ -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 diff --git a/sepolicy/vendor/file.te b/sepolicy/vendor/file.te index cbfa5c6b..27b2ebe7 100644 --- a/sepolicy/vendor/file.te +++ b/sepolicy/vendor/file.te @@ -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; diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts index 4c490d5a..a0e3a406 100644 --- a/sepolicy/vendor/genfs_contexts +++ b/sepolicy/vendor/genfs_contexts @@ -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 diff --git a/sepolicy/vendor/hal_power_default.te b/sepolicy/vendor/hal_power_default.te index 283c917d..83cee7a2 100644 --- a/sepolicy/vendor/hal_power_default.te +++ b/sepolicy/vendor/hal_power_default.te @@ -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;