1#!/system/bin/sh 2 3# sleep_exit [<exit_code>] 4function sleep_exit() { 5 # Sleep before exit to ensure logs flushes. 6 sleep 5s 7 exit $@ 8} 9 10# log_gki <priority> <message> 11function log_gki() { 12 log -t gki -p $@ 13} 14 15log_gki i "GKI APEX preinstall hook starting." 16 17mydir=$(dirname $(dirname $(realpath "$0"))) 18if [[ $(dirname $mydir) != "/apex" ]] || [[ $(basename $mydir) != com.android.gki.* ]]; then 19 log_gki e "This script must be installed under /apex/com.android.gki.*" 20 sleep_exit 1 21fi 22 23# The pre-installed APEX does not contain any OTA payload. Just skip installing anything. 24if [[ ! -f ${mydir}/etc/ota/payload.bin ]]; then 25 log_gki e "No payload.bin found." 26 sleep_exit 1 27fi 28 29log_gki i "Applying payload."; 30 31if ! ${mydir}/bin/update_engine_stable_client \ 32 --payload ${mydir}/etc/ota/payload.bin \ 33 --headers "$(cat ${mydir}/etc/ota/payload_properties.txt)"; then 34 log_gki e "OTA failed" 35 sleep_exit 1 36fi 37 38log_gki i "OTA successful" 39sleep_exit 0 40