1# This script captures MSKP files from RenderEngine in a connected device. 2# this only functions when RenderEngine uses the Skia backend. 3# it triggers code in SkiaCapture.cpp. 4 5# for a newly flashed device, perform first time steps with 6# record.sh rootandsetup 7 8# record all frames that RenderEngine handles over the span of 2 seconds. 9# record.sh 2000 10 11if [ -z "$1" ]; then 12 printf 'Usage:\n record.sh rootandsetup\n' 13 printf ' record.sh MILLISECONDS\n\n' 14 exit 1 15elif [ "$1" == "rootandsetup" ]; then 16 # first time use requires these changes 17 adb root 18 adb shell setenforce 0 19 adb shell stop 20 adb shell start 21 exit 1; 22fi 23 24check_permission() { 25 adb shell getenforce 26} 27 28mode=$(check_permission) 29 30if [ "$mode" != "Permissive" ]; then 31 echo "Cannot write to disk from RenderEngine. run 'record.sh rootandsetup'" 32 exit 5 33fi 34 35# record frames for some number of milliseconds. 36adb shell setprop debug.renderengine.capture_skia_ms $1 37 38# give the device time to both record, and starting writing the file. 39# Total time needed to write the file depends on how much data was recorded. 40# the loop at the end waits for this. 41sleep $(($1 / 1000 + 4)); 42 43# There is no guarantee that at least one frame passed through renderengine during that time 44# but as far as I know it always at least writes a 0-byte file with a new name, unless it crashes 45# the process it is recording. 46 47spin() { 48 case "$spin" in 49 1) printf '\b|';; 50 2) printf '\b\\';; 51 3) printf '\b-';; 52 *) printf '\b/';; 53 esac 54 spin=$(( ( ${spin:-0} + 1 ) % 4 )) 55 sleep $1 56} 57 58local_path=~/Downloads/ 59 60get_filename() { 61 adb shell getprop debug.renderengine.capture_filename 62} 63 64remote_path="" 65counter=0 # used to check only 1/sec though we update spinner 20/sec 66while [ -z $remote_path ] ; do 67 spin 0.05 68 counter=$(( $counter+1 )) 69 if ! (( $counter % 20)) ; then 70 remote_path=$(get_filename) 71 fi 72done 73printf '\b' 74 75printf "MSKP file serialized to: $remote_path\n" 76 77adb_pull_cmd="adb pull $remote_path $local_path" 78echo $adb_pull_cmd 79$adb_pull_cmd 80 81adb shell rm "$remote_path" 82printf 'SKP saved to %s\n\n' "$local_path" 83