# 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-L

# 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 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/mode_rate_limit_us "1"
    # 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
    chown system system /sys/devices/system/cpu/cpufreq/schedutil/*
    chmod 0644 /sys/devices/system/cpu/cpufreq/schedutil/*
    write /sys/devices/system/cpu/cpufreq/schedutil/mode_rate_limit_us "4"
    # scheduler TWEAK
    write /sys/block/mmcblk0/queue/scheduler cfq
    write /sys/block/sda/queue/scheduler cfq
    write /sys/block/sdc/queue/scheduler cfq
    # 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 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/mode_rate_limit_us "3"
    # scheduler TWEAK
    write /sys/block/mmcblk0/queue/scheduler cfq
    write /sys/block/sda/queue/scheduler cfq
    write /sys/block/sdc/queue/scheduler cfq
    # 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/mode_rate_limit_us "2"
    # scheduler TWEAK
    write /sys/block/mmcblk0/queue/scheduler cfq
    write /sys/block/sda/queue/scheduler cfq
    write /sys/block/sdc/queue/scheduler cfq
    # tweak thermal
    write /sys/class/thermal/thermal_message/sconfig 16