1#!/bin/bash 2# 3# android_run_skia: starts the correct skia program on the device, prints the 4# output, and kills the app if interrupted. 5 6SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 7source $SCRIPT_DIR/android_setup.sh 8source $SCRIPT_DIR/utils/setup_adb.sh 9 10if [ ! -f "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" ]; 11then 12 echo "Unable to find $BUILDTYPE ${APP_ARGS[0]} library" 13 exit 1 14fi 15 16adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/skia_launcher" /data/local/tmp 17if [ -f "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" ]; then 18 # Does not exist for builds with static skia. 19 adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" /data/local/tmp 20fi 21adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" /data/local/tmp 22 23STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)" 24$ADB ${DEVICE_SERIAL} shell \ 25 "/data/local/tmp/skia_launcher ${APP_ARGS[*]}; echo \$? > ${STATUS_FILENAME}" 26if [ -z "$($ADB $DEVICE_SERIAL shell 'if [ -f $STATUS_FILENAME ]; then echo exists; fi')" ]; then 27 echo "***********************************************************************" 28 echo "The application terminated unexpectedly and did not produce an exit code" 29 echo "***********************************************************************" 30 exit 1 31fi 32 33EXIT_CODE=`$ADB ${DEVICE_SERIAL} shell cat ${STATUS_FILENAME}` 34$ADB ${DEVICE_SERIAL} shell rm -f ${STATUS_FILENAME} 35 36# check to see if the 'cat' command failed and print errors accordingly 37if [[ ${EXIT_CODE} == *${STATUS_FILENAME}* ]]; then 38 echo "***********************************************************************" 39 echo "ADB failed to retrieve the application's exit code" 40 echo "***********************************************************************" 41 exit 1 42fi 43 44echo "EXIT_CODE is ${EXIT_CODE}" 45if [ $'0\r' != "${EXIT_CODE}" ]; then 46 exit 1 47fi 48exit 0 49