#!/bin/sh

export LD_PRELOAD=/usr/lib/libdebugger.so
# For UI Auto tp test
#export QWS_MOUSE_PROTO="IntelliMouse:/dev/input/mice"
# QT env
source /etc/profile

# Set touchscreen env if there is a tp device
# Grep the tp name (such as 'goodix-ts') to find out there is a tp.
# e.g. TS=`cat /proc/bus/input/devices | grep "touch-ts"`
#TS=`cat /proc/bus/input/devices | grep "chipone-ts"`
TS=`cat /proc/bus/input/devices | grep "goodix-ts"`
if [ -n "$TS" ];
then
  export QWS_MOUSE_PROTO="Tslib:/dev/input/event1 IntelliMouse:/dev/input/mice"
fi

case "$1" in
  start)
    logcat -v time -r4096 -f "/data/log/`date +%Y%m%d-%H-%M-%S.log`" &
    if [ -d "/data/ota/" ];then
      echo "clean /data/ota"
      rm -rf /data/ota/*
    fi
    aio -qws > /dev/null  &
    if [ -e "/data/stress_test.sh" ];then
	chmod 777 /data/stress_test.sh
	/data/stress_test.sh &
    fi
    #/etc/init.d/meminfo.sh > "/data/`date +%Y%m%d-%H-%M-%S.log`" &
    ;;
  stop)
    pgrep aio | xargs kill -15 
    sleep 5
    pgrep wpa_supplicant | xargs kill -9
    pgrep viss_isp | xargs kill -9
    pgrep rtk_hciattach | xargs kill -9
    sleep 1
    pgrep aio | xargs kill -9
    ;;
  *)
    ;;
esac
