# Initialization
on property:sys.boot_completed=1

# Set default profile on first boot
    exec u:r:init:s0 root root -- /vendor/bin/init.spectrum.sh
    exec u:r:magisk:s0 root root -- /vendor/bin/init.spectrum.sh
    exec u:r:su:s0 root root -- /vendor/bin/init.spectrum.sh

# Balance (default profile)
on property:persist.spectrum.profile=0
    # CPU
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "interactive"
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 652800
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 2016000
    write /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay "19000 1401600:39000"
    write /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load 85
    write /sys/devices/system/cpu/cpufreq/interactive/timer_rate 60000
    write /sys/devices/system/cpu/cpufreq/interactive/timer_slack 480000
    write /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq 1401600
    write /sys/devices/system/cpu/cpufreq/interactive/io_is_busy 0
    write /sys/devices/system/cpu/cpufreq/interactive/target_loads "80 652800:57 1036800:67 1401600:75 1689600:80 1843200:85 1958400:87"
    write /sys/devices/system/cpu/cpufreq/interactive/min_sample_time 39000
    write /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay 0
    write /sys/devices/system/cpu/cpufreq/interactive/min_sample_time 0
    write /sys/devices/system/cpu/cpufreq/interactive/ignore_hispeed_on_notif 0
    write /sys/devices/system/cpu/cpufreq/interactive/fast_ramp_down 0
    write /sys/devices/system/cpu/cpufreq/interactive/align_windows 1
    write /sys/devices/system/cpu/cpufreq/interactive/use_migration_notif 1
    write /sys/devices/system/cpu/cpufreq/interactive/enable_prediction 0
    write /sys/devices/system/cpu/cpufreq/interactive/max_freq_hysteresis 0
    write /sys/module/msm_performance/parameters/touchboost 1
    write /sys/module/workqueue/parameters/power_efficient Y

    # GPU
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/governor "msm-adreno-tz"
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/min_freq 133000000
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/max_freq 650000000
    write /sys/class/kgsl/kgsl-3d0/max_gpuclk 650000000

    # I/O Scheduler
    write /sys/block/mmcblk0/queue/read_ahead_kb 512
    write /sys/block/mmcblk0/queue/scheduler "cfq"

    # Set thermal restrictions
    write /sys/kernel/msm_thermal/enabled 0
    write /sys/kernel/msm_thermal/zone0 "1401600 1785600 40 38"
    write /sys/kernel/msm_thermal/zone1 "1324800 1555200 41 40"
    write /sys/kernel/msm_thermal/zone2 "1228800 1478400 42 41"
    write /sys/kernel/msm_thermal/zone3 "1228800 1401600 43 42"
    write /sys/kernel/msm_thermal/zone4 "1190400 1324800 44 43"
    write /sys/kernel/msm_thermal/zone5 "1190400 1248000 46 44"
    write /sys/kernel/msm_thermal/zone6 "1113600 1190400 48 46"
    write /sys/kernel/msm_thermal/zone7 "1036800 940800 53 50"
    write /sys/kernel/msm_thermal/zone8 "729600 729600 65 60"
    write /sys/kernel/msm_thermal/sampling_ms 8000
    write /sys/kernel/msm_thermal/enabled 1

# Performance
on property:persist.spectrum.profile=1
    # CPU
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "blu_active"
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 652800
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 2016000
    write /sys/module/msm_performance/parameters/touchboost 1
    write /sys/module/workqueue/parameters/power_efficient N

    # GPU
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/governor "msm-adreno-tz"
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/min_freq 133000000
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/max_freq 700000000
    write /sys/class/kgsl/kgsl-3d0/max_gpuclk 700000000

    # I/O Scheduler
    write /sys/block/mmcblk0/queue/read_ahead_kb 2048
    write /sys/block/mmcblk0/queue/scheduler "tripndroid"

# Battery
on property:persist.spectrum.profile=2
    # CPU
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "alucard"
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 652800
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 1689600
    write /sys/module/msm_performance/parameters/touchboost 0
    write /sys/module/workqueue/parameters/power_efficient Y

    # GPU
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/governor "powersave"
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/min_freq 133000000
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/max_freq 510000000
    write /sys/class/kgsl/kgsl-3d0/max_gpuclk 510000000

    # I/O Scheduler
    write /sys/block/mmcblk0/queue/read_ahead_kb 128
    write /sys/block/mmcblk0/queue/scheduler "anxiety"

# Gaming
on property:persist.spectrum.profile=3
    # CPU
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "performance"
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 652800
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 2016000
    write /sys/module/msm_performance/parameters/touchboost 1
    write /sys/module/workqueue/parameters/power_efficient N

    # GPU
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/governor "performance"
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/min_freq 133000000
    write /sys/devices/soc/1c00000.qcom,kgsl-3d0/devfreq/1c00000.qcom,kgsl-3d0/max_freq 700000000
    write /sys/class/kgsl/kgsl-3d0/max_gpuclk 700000000

    # I/O Scheduler
    write /sys/block/mmcblk0/queue/read_ahead_kb 2048
    write /sys/block/mmcblk0/queue/scheduler "deadline"
