| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | # Copyright 2015 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | # |
| 8 | # Before this can be used, the device must be rooted and the filesystem must be writable by Skia |
| 9 | # - These steps are necessary once after flashing to enable capture - |
| 10 | # adb root |
| 11 | # adb remount |
| 12 | # adb reboot |
| 13 | |
| 14 | if [scip-shell system . . `[`. -z "$1" ]; then |
| 15 | printfscip-shell system . . printf. 'Usage:\n skp-capture.sh PACKAGE_NAME OPTIONAL_FRAME_COUNT\n\n' |
| 16 | printfscip-shell system . . printf. "Use \`adb shell 'pm list packages'\` to get a listing.\n\n" |
| 17 | exit 1 |
| 18 | fi |
| 19 | if ! command -v adb > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then |
| 20 | if [scip-shell system . . `[`. -x "${ANDROID_SDK_ROOT}/platform-tools/adb" ]; then |
| 21 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb().() { |
| 22 | "${ANDROID_SDK_ROOT}/platform-tools/adb" "$@" |
| 23 | } |
| 24 | else |
| 25 | echoscip-shell system . . echo. 'adb missing' |
| 26 | exit 2 |
| 27 | fi |
| 28 | fi |
| 29 | phase1_timeout_seconds=60 |
| 30 | phase2_timeout_seconds=300 |
| 31 | package="$1" |
| 32 | extension="skp" |
| 33 | if (( "$2" > 1 )); then # 2nd arg is number of frames |
| 34 | extension="mskp" # use different extension for multi frame files. |
| 35 | fi |
| 36 | filename="$(datescip-shell system . . date. '+%H%M%S').${extension}" |
| 37 | remote_path="/data/data/${package}/cache/${filename}" |
| 38 | local_path_prefix="$(datescip-shell system . . date. '+%Y-%m-%d_%H%M%S')_${package}" |
| 39 | local_path="${local_path_prefix}.${extension}" |
| 40 | enable_capture_key='debug.hwui.capture_skp_enabled' |
| 41 | enable_capture_value=$(adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "getprop '${enable_capture_key}'") |
| 42 | |
| 43 | # TODO(nifong): check if filesystem is writable here with "avbctl get-verity" |
| 44 | # result will either start with "verity is disabled" or "verity is enabled" |
| 45 | |
| 46 | if [scip-shell system . . `[`. -z "$enable_capture_value" ]; then |
| 47 | printfscip-shell system . . printf. 'debug.hwui.capture_skp_enabled was found to be disabled, enabling it now.\n' |
| 48 | printfscip-shell system . . printf. " restart the process you want to capture on the device, then retry this script.\n\n" |
| 49 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "setprop '${enable_capture_key}' true" |
| 50 | exit 1 |
| 51 | fi |
| 52 | if [scip-shell system . . `[`. ! -z "$2" ]; then |
| 53 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "setprop 'debug.hwui.capture_skp_frames' $2" |
| 54 | fi |
| 55 | filename_key='debug.hwui.skp_filename' |
| 56 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "setprop '${filename_key}' '${remote_path}'" |
| 57 | spinscip-shell shell android-platform-frameworks-base 1:14~beta1-5 spin().() { |
| 58 | case "$spin" in |
| 59 | 1) printfscip-shell system . . printf. '\b|';; |
| 60 | 2) printfscip-shell system . . printf. '\b\\';; |
| 61 | 3) printfscip-shell system . . printf. '\b-';; |
| 62 | *) printfscip-shell system . . printf. '\b/';; |
| 63 | esac |
| 64 | spin=$(( ( ${spin:-0} + 1 ) % 4 )) |
| 65 | sleepscip-shell system . . sleep. $1 |
| 66 | } |
| 67 | |
| 68 | bannerscip-shell shell android-platform-frameworks-base 1:14~beta1-5 banner().() { |
| 69 | printfscip-shell system . . printf. '\n=====================\n' |
| 70 | printfscip-shell system . . printf. ' %s' "$*" |
| 71 | printfscip-shell system . . printf. '\n=====================\n' |
| 72 | } |
| 73 | bannerscip-shell shell android-platform-frameworks-base 1:14~beta1-5 banner(). '...WAITING FOR APP INTERACTION...' |
| 74 | # Waiting for nonzero file is an indication that the pipeline has both opened the file and written |
| 75 | # the header. With multiple frames this does not occur until the last frame has been recorded, |
| 76 | # so we continue to show the "waiting for app interaction" message as long as the app still requires |
| 77 | # interaction to draw more frames. |
| 78 | adb_test_file_nonzeroscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb_test_file_nonzero().() { |
| 79 | # grab first byte of `wc -c` output |
| 80 | X="$(adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "wc -c \"$1\" 2> /dev/null | dd bs=1 count=1 2> /dev/null")" |
| 81 | testscip-shell system . . test. "$X" && testscip-shell system . . test. "$X" -ne 0 |
| 82 | } |
| 83 | timeout=$(( $(datescip-shell system . . date. +%s) + $phase1_timeout_seconds)) |
| 84 | while ! adb_test_file_nonzeroscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb_test_file_nonzero(). "$remote_path"; do |
| 85 | spinscip-shell shell android-platform-frameworks-base 1:14~beta1-5 spin(). 0.05 |
| 86 | if [scip-shell system . . `[`. $(datescip-shell system . . date. +%s) -gt $timeout ] ; then |
| 87 | printfscip-shell system . . printf. '\bTimed out.\n' |
| 88 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "setprop '${filename_key}' ''" |
| 89 | exit 3 |
| 90 | fi |
| 91 | done |
| 92 | printfscip-shell system . . printf. '\b' |
| 93 | |
| 94 | # Disable further capturing |
| 95 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "setprop '${filename_key}' ''" |
| 96 | |
| 97 | bannerscip-shell shell android-platform-frameworks-base 1:14~beta1-5 banner(). '...SAVING...' |
| 98 | # return the size of a file in bytes |
| 99 | adb_filesizescip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb_filesize().() { |
| 100 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "wc -c \"$1\"" 2> /dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '{print $1}' |
| 101 | } |
| 102 | timeout=$(( $(datescip-shell system . . date. +%s) + $phase2_timeout_seconds)) |
| 103 | last_size='0' # output of last size check command |
| 104 | unstable=true # false once the file size stops changing |
| 105 | counter=0 # used to perform size check only 1/sec though we update spinner 20/sec |
| 106 | # loop until the file size is unchanged for 1 second. |
| 107 | while [scip-shell system . . `[`. $unstable != 0 ] ; do |
| 108 | spinscip-shell shell android-platform-frameworks-base 1:14~beta1-5 spin(). 0.05 |
| 109 | counter=$(( $counter+1 )) |
| 110 | if ! (( $counter % 20)) ; then |
| 111 | new_size=$(adb_filesizescip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb_filesize(). "$remote_path") |
| 112 | unstable=$(($(adb_filesizescip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb_filesize(). "$remote_path") != last_size)) |
| 113 | last_size=$new_size |
| 114 | fi |
| 115 | if [scip-shell system . . `[`. $(datescip-shell system . . date. +%s) -gt $timeout ] ; then |
| 116 | printfscip-shell system . . printf. '\bTimed out.\n' |
| 117 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell "setprop '${filename_key}' ''" |
| 118 | exit 3 |
| 119 | fi |
| 120 | done |
| 121 | printfscip-shell system . . printf. '\b' |
| 122 | |
| 123 | printfscip-shell system . . printf. "SKP file serialized: %s\n" $(echoscip-shell system . . echo. $last_size | numfmtscip-shell system . . numfmt. --to=iec) |
| 124 | |
| 125 | i=0; while [scip-shell system . . `[`. $i -lt 10 ]; do spinscip-shell shell android-platform-frameworks-base 1:14~beta1-5 spin(). 0.10; i=$(($i + 1)); done; echoscip-shell system . . echo. |
| 126 | |
| 127 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). pull "$remote_path" "$local_path" |
| 128 | if ! [scip-shell system . . `[`. -f "$local_path" ] ; then |
| 129 | printfscip-shell system . . printf. "something went wrong with `adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). pull`." |
| 130 | exit 4 |
| 131 | fi |
| 132 | adbscip-shell shell android-platform-frameworks-base 1:14~beta1-5 adb(). shell rm "$remote_path" |
| 133 | printfscip-shell system . . printf. '\nSKP saved to file:\n %s\n\n' "$local_path" |
| 134 |