1 #! /bin/bash 2 #This script does a clean build of PMC and install it to your device through adb 3 #Requires envsetup.sh in the branch 4 5 #function to change jdk version 6 function setup_jdk() { 7 # Remove the current JDK from PATH 8 if [ -n "$JAVA_HOME" ] ; then 9 PATH=${PATH/$JAVA_HOME\/bin:/} 10 fi 11 export JAVA_HOME=$1 12 export PATH=$JAVA_HOME/bin:$PATH 13 } 14 15 #Color code for echo 16 r='\e[0;31m' 17 brn='\e[0;33m' 18 y='\e[1;33m' 19 g='\e[0;32m' 20 cy='\e[0;36m' 21 lb='\e[1;34m' 22 p='\e[0;35m' 23 lg='\e[0;37m' 24 NC='\e[0m' # No Color 25 26 echo -e "Welcome to ${r}U${brn}N${y}I${g}C${lb}O${cy}R${p}N${NC} build system for ${g}PMC${NC}" 27 28 IFS='_' read -a array <<< "$TARGET_PRODUCT" 29 export TP=${array[0]} 30 if [[ ${#array[@]} -eq 2 ]]; then 31 export TP=${array[1]} 32 fi 33 34 APP_NAME=PMC 35 APP_PACKAGE_NAME=com.android.pmc 36 37 BRANCH_ROOT=$PWD/../../../../.. 38 PMC_PROJ=$BRANCH_ROOT/vendor/google_testing/comms/Tools/PMC 39 SHARED_LIB_JAR_ROOT=$BRANCH_ROOT/out/target/common/obj/JAVA_LIBRARIES 40 APP_JAR_ROOT=$BRANCH_ROOT/out/target/common/obj/APPS 41 APK_ROOT=$BRANCH_ROOT/out/target/product/$TP/system/priv-app/PMC 42 43 function pmc_build { 44 45 echo -e "${y}Removing intermeidates of the app${NC}" 46 rm -r $APP_JAR_ROOT/"$APP_NAME"_intermediates 47 #Remove the apk file 48 rm $APK_ROOT/"$APP_NAME".apk 49 50 #Build all the dependency libs 51 . $BRANCH_ROOT/build/envsetup.sh 52 53 exec () { 54 ${@:1:($#-1)} 55 if [ $? -ne 0 ]; then 56 echo -e "${r}Encountered error when ${@:$#}${NC}" 57 echo -e "${lg}UNICORN ${r}DIED${NC}!" 58 exit 1 59 fi 60 } 61 62 echo -e "${lb}+++++++ Building $APP_NAME.apk +++++++${NC}" 63 cd $PMC_PROJ 64 exec mm -B "building $APP_NAME.apk" 65 echo 66 67 } 68 69 function pmc_flash { 70 71 echo -e "${y}Switching to root${NC}" 72 adb root 73 adb wait-for-device remount 74 75 echo -e "${y}Uninstalling old apk from device${NC}" 76 adb uninstall $APP_PACKAGE_NAME 77 adb shell rm -r /system/priv-app/$APP_NAME.apk 78 79 echo -e "${lb}Installing apk to device${NC}" 80 cd $APK_ROOT 81 #exec adb install $APP_NAME.apk "installing apk to device" 82 #exec adb push $APP_NAME.apk /system/priv-app "installing apk to previliged dir" 83 exec adb install -r $APP_NAME.apk "installing apk to previliged dir" 84 85 } 86 87 DO_BUILD=1 88 DO_FLASH=1 89 90 if [ $# -ne 0 ] ; then 91 DO_BUILD=0 92 DO_FLASH=0 93 while getopts "bf" ARG 94 do 95 case $ARG in 96 b) DO_BUILD=1 && echo "Build it we will.";; 97 f) DO_FLASH=1 && echo "Flash it we must.";; 98 ?) echo "Invalid Argument ${ARG}" && exit 1;; 99 esac 100 done 101 fi 102 103 if [ ${DO_BUILD} -eq "1" ] ; then 104 pmc_build 105 fi 106 107 if [ ${DO_FLASH} -eq "1" ] ; then 108 pmc_flash 109 fi 110 111 echo "All clear!" 112 echo -e " ${r}U${brn}N${y}I${g}C${cy}O${lb}R${p}N ${r}P${brn}O${y}W${g}E${cy}R${lb}!${p}!${NC}" 113 114