#!/system/bin/sh

# ===========================================================================
#  Virtuous ROM Tools (rmk)
#
#  $LastChangedDate: 2011-08-19 20:21:30 +0200 (Fr, 19 Aug 2011) $
# ===========================================================================

. /system/virtuous/scripts/virtuous-functions.sh

OC_APPS="ch.amana.android.cputuner com.mhuang.overclocking org.freecoder.widgets.overclock com.antutu.CpuMasterFree"

$LOG -p i "Executing optimization script"

# Force standard memory tunables.

cat > /data/local.prop <<EOF 
ro.HOME_APP_ADJ=0
ro.FOREGROUND_APP_MEM 2048
ro.HOME_APP_MEM=3072
ro.VISIBLE_APP_MEM 3072
ro.PERCEPTIBLE_APP_MEM 4096
ro.HEAVY_WEIGHT_APP_MEM 4096
ro.SECONDARY_SERVER_MEM 6144
ro.BACKUP_APP_MEM 6144
ro.HIDDEN_APP_MEM 6144
ro.EMPTY_APP_MEM 8192
EOF

# Tune low memory killer.

$ECHO '1024,2048,4096,5120,6144,8192' > \
    /sys/module/lowmemorykiller/parameters/minfree

# Increase readahead buffers on MMC devices

$ECHO 1024 > /sys/block/mmcblk0/bdi/read_ahead_kb
$ECHO 1024 > /sys/block/mmcblk1/bdi/read_ahead_kb

# Check whether any cpu tuning apps are already installed.
# If not, we'll start our custom daemon.

OC_KERNEL=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

if ! $TEST -e $OC_KERNEL ; then
    $LOG -p i "Kernel does not support overclocking; disabling Virtuous_OC"
    exit 1
fi

if is_package_installed $OC_APPS ; then
    $LOG -p i "User-installed overclocking app detected; disabled Virtuous_OC"
else
    $LOG -p i "No overclocking apps detected; enabling Virtuous_OC"
    /system/xbin/virtuous_oc
fi

