#!/system/bin/sh

MODPATH=/data/adb/modules/snapfest

mkdir -p "$MODPATH"/system/lib/egl
mkdir -p "$MODPATH"/system/lib64/egl
mkdir -p "$MODPATH"/system/vendor/lib/egl
mkdir -p "$MODPATH"/system/vendor/lib64/egl

model=$(cat /sys/class/kgsl/kgsl-3d0/gpu_model)
config="0 1 $model"

echo "$config" > "$MODPATH"/system/lib/egl/egl.cfg
echo "$config" > "$MODPATH"/system/lib64/egl/egl.cfg
echo "$config" > "$MODPATH"/system/vendor/lib/egl/egl.cfg
echo "$config" > "$MODPATH"/system/vendor/lib64/egl/egl.cfg

echo "0" > /sys/block/sda/queue/iostats
echo "0" > /sys/block/loop1/queue/iostats
echo "0" > /sys/block/loop2/queue/iostats
echo "0" > /sys/block/loop3/queue/iostats
echo "0" > /sys/block/loop4/queue/iostats
echo "0" > /sys/block/loop5/queue/iostats
echo "0" > /sys/block/loop6/queue/iostats
echo "0" > /sys/block/loop7/queue/iostats
echo "0" > /sys/block/dm-0/queue/iostats
echo "0" > /sys/block/loop0/queue/iostats
echo "0" > /sys/block/mmcblk1/queue/iostats
echo "0" > /sys/block/mmcblk0/queue/iostats
echo "0" > /sys/block/mmcblk0rpmb/queue/iostats

echo "N" > /sys/module/kernel/parameters/initcall_debug
echo "0" > /sys/module/printk/parameters/console_suspend
echo "bbr" > /sys/module/tcp_bbr/parameters/tcp_congestion_control

set_properties="
ro.hwui.render_ahead=true
ro.ui.pipeline=skiaglthreaded
persist.sys.egl.swapinterval=1
ro.vendor.perf.scroll_opt=true
persist.sys.purgeable_assets=1
dalvik.vm.execution-mode=int:jit
vendor.perf.framepacing.enable=1
dalvik.vm.dex2oat-filter=everything
persist.sys.debug.gr.swapinterval=1
ro.hwui.hardware.skiaglthreaded=true
persist.sys.dalvik.hyperthreading=true
dalvik.vm.image-dex2oat-filter=everything
persist.sys.perf.topAppRenderThreadBoost.enable=true
"

reset_properties="
sys.use_fifo_ui=1
ro.min_pointer_dur=8
ro.iorapd.enable=false
ro.min.fling_velocity=8000
persist.sys.lgospd.enable=0
persist.sys.pcsync.enable=0
persist.sys.scrollingcache=2
persist.sys.perf.debug=false
ro.max.fling_velocity=20000
windowsmgr.max_event_per_sec=200
ro.surface_flinger.protected_contents=true
persist.vendor.verbose_logging_enabled=false
ro.surface_flinger.has_wide_color_display=true
ro.surface_flinger.use_color_management=true
persist.sys.turbosched.enable.coreApp.optimizer=true
persist.device_config.runtime_native_boot.iorap_perfetto_enable=false
persist.device_config.runtime_native_boot.iorap_readahead_enable=false
"

for prop in $set_properties; do
    prop_name="${prop%%=*}"
    prop_value="${prop#*=}"
    setprop "$prop_name" "$prop_value"
done

for prop in $reset_properties; do
    prop_name="${prop%%=*}"
    prop_value="${prop#*=}"
    resetprop -n "$prop_name" "$prop_value"
done
