#!/bin/sh
#
# This file is part of osso-af-startup.
#
# Copyright (C) 2004-2007 Nokia Corporation. All rights reserved.
#
# Contact: Kimmo Hmlinen <kimmo.hamalainen@nokia.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License 
# version 2 as published by the Free Software Foundation. 
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA

# Exclude some UIDs from memory allocation denial.
UIDS=`getent passwd haldaemon systemui messagebus | cut -d: -f3`
echo "Protecting UIDs $UIDS from the memory allocation denial."
echo $UIDS > /proc/sys/vm/lowmem_allowed_uids

# activate lowmem module
echo 92 > /proc/sys/vm/lowmem_deny_watermark
echo 85 > /proc/sys/vm/lowmem_notify_high
echo 512 > /proc/sys/vm/lowmem_nr_decay_pages
echo 80 > /proc/sys/vm/lowmem_notify_low

# adjust other kernel parameters to minimize memory consumption 
echo 4 > /proc/sys/kernel/pty/max
echo 256 > /proc/sys/kernel/threads-max
echo 4096 > /proc/sys/fs/file-max
echo 1 > /proc/sys/vm/swappiness

# adjust flushing of memory card buffers
echo 12 > /proc/sys/vm/dirty_ratio
echo 6 > /proc/sys/vm/dirty_background_ratio

SCRIPT=/etc/osso-af-init/real-af-services

case "$1" in
start)  su - user $SCRIPT start
        # if device lock is on, stop the progress bar
        TMP=`/etc/osso-af-init/get-devlock.sh`
        if [ "x$TMP" != "xunlocked" ]; then
          /etc/init.d/fb-progress.sh stop
        fi 
        ;;
stop)   su - user $SCRIPT stop
        ;;
restart)
        echo "$0: not implemented"
        exit 1
        ;;
force-reload)
        echo "$0: not implemented"
        exit 1
        ;;
*)      echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac
