#!/system/bin/sh
logcat -c
input keyevent KEYCODE_WAKEUP
settings put system screen_off_timeout 600000
am force-stop my.com.tngdigital.ewallet
sleep 1
monkey -p my.com.tngdigital.ewallet -c android.intent.category.LAUNCHER 1 >/dev/null 2>&1
i=0
while [ $i -lt 40 ]; do
  sleep 1
  i=$((i+1))
  p=$(pidof my.com.tngdigital.ewallet)
  if [ -z "$p" ]; then
    echo "t=${i}s DEAD"
    break
  fi
  if [ $((i % 5)) -eq 0 ]; then
    echo "t=${i}s pid=$p"
  fi
done
echo "=== focus ==="
dumpsys window 2>/dev/null | grep -E 'mCurrentFocus|mFocusedApp' | head -4
echo "=== key ==="
logcat -d 2>/dev/null | grep -E 'TngExitGuard|Displayed.*User|UserPin|UserLogin|seccomp|caught sig=|exited cleanly|Fatal signal|ANR in my.com.tng' | tail -40
