# kernel manaeger,inspired from SPECTRUM KERNEL MANAGER
# by ZyCromerZ @ 2020

# Initialization
on property:sys.boot_completed=1
    setprop spectrum.support 1
    setprop sys.display-size 3840x2160
    # chown
    chown system system /sys/devices/system/cpu/cpufreq/policy0/*
    chown system system /sys/devices/system/cpu/cpufreq/policy6/*
    chown system system /sys/block/mmcblk0/queue/*
    chown system system /sys/block/sda/queue/*
    chown system system /sys/block/sdb/queue/*
    chown system system /sys/block/sdc/queue/*
    # chmod
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy0/*
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy6/*
    chmod 0644 /sys/block/mmcblk0/queue/*
    chmod 0644 /sys/block/sda/queue/*
    chmod 0644 /sys/block/sdb/queue/*
    chmod 0644 /sys/block/sdc/queue/*
    # tweak thermal
    write /sys/class/thermal/thermal_message/sconfig 1
    # for set mode spectrum
    setprop persist.spectrum.profile 0
    setprop persist.spectrum.kernel QuantumKiller-N

# Battery
on property:persist.spectrum.profile=2
    # CPU TWEAK
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy0/scaling_governor conservative
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy6/scaling_governor conservative
    restorecon -R /sys/devices/system/cpu
    chown system system /sys/devices/system/cpu/cpufreq/conservative/*
    chmod 0644 /sys/devices/system/cpu/cpufreq/conservative/*
    write /sys/devices/system/cpu/cpufreq/conservative/up_threshold "95"
    write /sys/devices/system/cpu/cpufreq/conservative/sampling_rate "120000"
    write /sys/devices/system/cpu/cpufreq/conservative/sampling_down_factor "1"
    write /sys/devices/system/cpu/cpufreq/conservative/down_threshold "40"
    write /sys/devices/system/cpu/cpufreq/conservative/freq_step "10"
    # scheduler TWEAK
    write /sys/block/mmcblk0/queue/scheduler anxiety
    write /sys/block/sda/queue/scheduler anxiety
    write /sys/block/sdc/queue/scheduler anxiety
    # tweak thermal
    write /sys/class/thermal/thermal_message/sconfig 1

# balance
on property:persist.spectrum.profile=0
    # CPU TWEAK
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy0/scaling_governor schedutil
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy6/scaling_governor schedutil
    restorecon -R /sys/devices/system/cpu
    # scheduler TWEAK
    write /sys/block/mmcblk0/queue/scheduler bfq
    write /sys/block/sda/queue/scheduler bfq
    write /sys/block/sdc/queue/scheduler bfq
    # tweak thermal
    write /sys/class/thermal/thermal_message/sconfig 1

# Gaming
on property:persist.spectrum.profile=3
    # CPU TWEAK
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy0/scaling_governor interactive
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy6/scaling_governor interactive
    restorecon -R /sys/devices/system/cpu
    # scheduler TWEAK
    write /sys/block/mmcblk0/queue/scheduler bfq
    write /sys/block/sda/queue/scheduler bfq
    write /sys/block/sdc/queue/scheduler bfq
    # tweak thermal
    write /sys/class/thermal/thermal_message/sconfig 2

# Performance
on property:persist.spectrum.profile=1
    # CPU TWEAK
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy0/scaling_governor schedutil
    chmod 0644 /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
    write /sys/devices/system/cpu/cpufreq/policy6/scaling_governor schedutil
    restorecon -R /sys/devices/system/cpu
    chown system system /sys/devices/system/cpu/cpufreq/schedutil/*
    chmod 0644 /sys/devices/system/cpu/cpufreq/schedutil/*
    write /sys/devices/system/cpu/cpufreq/schedutil/down_rate_limit_us "9000"
    write /sys/devices/system/cpu/cpufreq/schedutil/up_rate_limit_us "0"
    # scheduler TWEAK
    write /sys/block/mmcblk0/queue/scheduler bfq
    write /sys/block/sda/queue/scheduler bfq
    write /sys/block/sdc/queue/scheduler bfq
    # tweak thermal
    write /sys/class/thermal/thermal_message/sconfig 16