0% found this document useful (0 votes)
37 views3 pages

Android Power Save Mode Script

This shell script is designed for system initialization and maintenance on Android devices, including functions for writing settings, trimming partitions, and deleting unnecessary logs. It reads configuration properties from a specified file and applies them, while also managing game performance settings based on the device's manufacturer. The script includes error handling and ensures that operations are executed in the background to avoid user interruption.

Uploaded by

kp8486196
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

Android Power Save Mode Script

This shell script is designed for system initialization and maintenance on Android devices, including functions for writing settings, trimming partitions, and deleting unnecessary logs. It reads configuration properties from a specified file and applies them, while also managing game performance settings based on the device's manufacturer. The script includes error handling and ensures that operations are executed in the background to avoid user interruption.

Uploaded by

kp8486196
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#!

/sbin/sh

#################
# Initialization
#################

# echo before loading util_functions


ui_print() { echo "$1"; }

# Generalized function to handle system, secure, and global settings


write() {
case "$1" in
system)
settings put system "$2" "$3"
;;
secure)
settings put secure "$2" "$3"
;;
global)
settings put global "$2" "$3"
;;
*)
echo "Invalid type: $1. Use 'system', 'secure', or 'global'."
;;
esac
}

MODDIR=/sdcard/Kazu/common/
ANDROIDVERSION=$(getprop [Link])
DEVICES=$(getprop [Link])
MANUFACTURER=$(getprop [Link])
API=$(getprop [Link])
FPS=$(dumpsys display | grep -oE 'fps=[0-9]+' | awk -F '=' '{print $2}' | head -n
1)
GAME=/sdcard/kazu/system/etc/[Link]
MIUI="grep miui"

# trimming
trim_partition () {
fstrim -v /system
sleep 0.1
fstrim -v /vendor
sleep 0.1
fstrim -v /data
sleep 0.1
fstrim -v /cache
sleep 0.1
fstrim -v /metadata
sleep 0.1
fstrim -v /odm
sleep 0.1
fstrim -v /system_ext
sleep 0.1
fstrim -v /product
sleep 0.1
sm fstrim
}

# delete trash & log by @Bias_khaliq


delete_trash_logs () {
# Clear trash on /data/data
for DIR in /data/data/*; do
if [ -d "${DIR}" ]; then
rm -rf ${DIR}/cache/*
rm -rf ${DIR}/no_backup/*
rm -rf ${DIR}/app_webview/*
rm -rf ${DIR}/code_cache/*
fi
done

# Delete Logs
rm -rf /data/{anr,log,tombstones,log_other_mode}/* \
/cache/*.{apk,tmp} \
/dev/log/* \
/data/system/{dropbox,usagestats,package_cache}/* \
/sys/kernel/debug/* \
/data/local/tmp* \
/data/dalvik-cache \
/data/media/0/{DCIM,Pictures,Music,Movies}/.thumbnails \
/data/media/0/{mtklog,MIUI/Gallery,MIUI/.debug_log,MIUI/BugReportCache} \
/data/vendor/thermal/{config,*.dump,*_history*.dump}
}

settingsproperties() {
# Path to the configuration file
CONFIG_FILE="/sdcard/kazu/common/[Link]"

# Read the configuration file line by line


while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines or comments
[ -z "$line" ] && continue
[ "${line:0:1}" = "#" ] && continue

# Parse key and value


key="${line%%=*}"
value="${line#*=}"

# Apply the property using setprop


setprop "$key" "$value"
done < "$CONFIG_FILE"
}

install_script() {
nohup sh /$MODDIR/[Link] &>/dev/null
nohup sh /$MODDIR/[Link] &>/dev/null
nohup sh /$MODDIR/[Link] &>/dev/null
settingsproperties &>/dev/null
}

cleanup_tweak() {
game_manager() {
if [ -z "$GAME" ] || [ ! -f "$GAME" ]; then
ui_print "File GAME tidak ditemukan atau tidak ditentukan."
return 1
fi

while IFS= read -r game; do


[ -z "$game" ] && continue
cmd game mode standard "$game" set --fps "$FPS"

done < "$GAME"


}
if ( getprop | $MIUI ); then
write system POWER_BALANCED_MODE_OPEN 1
write system POWER_PERFORMANCE_MODE_OPEN 0
write system POWER_SAVE_MODE_OPEN 0
write system power_mode middle
write system POWER_SAVE_PRE_HIDE_MODE enhance
write system POWER_SAVE_PRE_SYNCHRONIZE_ENABLE 1
else
sleep 0.0
fi
am memory-factor reset
write global activity_manager_constants 0
write global activity_starts_logging_enabled 1
write secure high_priority 0
cmd display ab-logging-enable
cmd display dwb-logging-enable
cmd looper_stats reset
cmd power set-adaptive-power-saver-enabled true
cmd power set-fixed-performance-mode-enabled false
cmd thermalservice reset
settings delete system peak_refresh_rate
settings delete system user_refresh_rate
settings delete system max_refresh_rate
settings delete system min_refresh_rate
game_manager
}

Common questions

Powered by AI

The 'settingsproperties' function allows for dynamic configuration by reading key-value pairs from a designated configuration file ('system.prop'). It parses each line, ignoring empty lines and comments, and applies properties using the 'setprop' command. This approach allows system administrators to easily modify system properties without altering the core script. By abstracting configuration details to an external file, system management becomes more flexible and less error-prone, enabling rapid adaptation to new requirements or environments without the need for direct script modification .

The 'game_manager' function is designed to optimize the gaming experience by reading a list of games from 'gamelist.txt' and setting game modes using the 'cmd game' command. It adjusts each game's frame per second (FPS) setting to match the device's capabilities. By doing so, the function ensures that games run smoothly with appropriate resource allocation, minimizing lag and improving visual performance. Such targeted optimization can significantly enhance user satisfaction by providing a more consistent and immersive gaming experience on devices configured with these settings .

The 'settings delete' commands in the 'cleanup_tweak' function remove specific system settings related to display refresh rates such as 'peak_refresh_rate', 'user_refresh_rate', 'max_refresh_rate', and 'min_refresh_rate'. By removing these settings, the script aims to reset the system to default state regarding refresh rates, which can prevent inconsistent or incorrectly applied configurations that may have been set outside standard parameters. This helps in optimizing the display performance by reducing issues that might arise from misconfigured settings, leading to a smoother visual experience without unintended variability in refresh rates .

The 'cleanup_tweak' function poses several risks, particularly in relation to user data and overall system functionality. It aggressively deletes system logs, cache files, and certain kernel debug information which, while freeing space and potentially improving performance, may also remove essential diagnostic data needed for system troubleshooting. Moreover, by resetting and removing key system settings such as display refresh rates without user confirmation, it could inadvertently disrupt user preferences and application-specific settings, leading to unexpected behavior post-cleanup. Therefore, while beneficial for maintenance, executing this function carries the risk of compromising data needed for recovery and may affect system behavior adversely if not carefully managed .

The 'delete_trash_logs' function potentially enhances system stability and manages storage efficiently by removing unnecessary cache, logs, and temporary files from the system. By clearing directories like /data/data, /data/system/dropbox, and various log locations, it frees up space and can mitigate issues caused by disk space shortage and excessive log data accumulation. However, improper use of this function could inadvertently delete useful data or logs necessary for troubleshooting, which may negatively impact data recovery processes or hinder post-crash analysis. Thus, careful implementation is crucial to balance between freeing up resources and maintaining useful data .

The 'trim_partition' function in the script improves system performance by executing the 'fstrim' command on multiple system partitions such as /system, /vendor, and /data. This command reclaims unused blocks on a filesystem, which helps in reducing fragmentation and improving data write speed. The potential benefits include faster read and write operations, extended SSD lifespan, and overall improvement in system responsiveness .

The 'install_script' function is crucial for executing system modifications post-startup by initiating other scripts ('post-fs-data.sh', 'service.sh', and 'system.prop') and applying settings through 'settingsproperties'. This function ensures that necessary settings and custom functionalities are automatically activated whenever the system starts, reducing the need for manual intervention. It facilitates consistent application of system tweaks and configurations across reboots, enhancing reliability and user experience by ensuring that the environment is correctly set up for intended usage immediately after booting .

The script uses the command 'getprop' in conjunction with 'grep miui' to determine if the MIUI operating system is in use. This conditional check allows the script to execute different blocks of code based on whether the current system is running MIUI. If it detects MIUI, the script sets various system power modes using the 'write' method. This adaptive behavior ensures that system settings are optimized specifically for the characteristics of MIUI, such as power balance and performance mode adjustments, thereby improving compatibility and efficiency .

The 'write' method in the script handles the configuration of system settings by categorizing them into three types: 'system', 'secure', and 'global'. It uses the 'settings put' command to modify these settings by taking three arguments: the type of setting, the specific setting key, and the value to be set. This method contributes to system configuration by providing a standardized way to alter system behaviors or states, depending on the arguments passed to it, thus making it easier to manage and automate system settings adjustments .

The script manages system power modes by employing the 'write' function to set various power-related configurations such as 'POWER_BALANCED_MODE_OPEN', 'POWER_PERFORMANCE_MODE_OPEN', and 'POWER_SAVE_MODE_OPEN'. Depending on the MIUI check, it adjusts the power mode, potentially configuring the system to operate in a 'balanced', 'performance', or 'power save' state. These adjustments influence how the device allocates resources, affecting both performance and battery life. Enhanced performance modes may increase responsiveness and processing power at the cost of battery life, whereas power save modes extend battery duration by limiting performance. Balancing these modes can optimize device usage based on user preference or scenario requirements .

You might also like