OLD | NEW |
(Empty) | |
| 1 #!/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 if [ -z "$1" ]; then |
| 9 printf 'Usage:\n android_skp_capture.sh PACKAGE_NAME\n\n' |
| 10 printf "Use \`adb shell 'pm list packages'\` to get a listing.\n\n" |
| 11 exit 1 |
| 12 fi |
| 13 if ! command -v adb > /dev/null 2>&1; then |
| 14 if [ -x "${ANDROID_SDK_ROOT}/platform-tools/adb" ]; then |
| 15 adb() { |
| 16 "${ANDROID_SDK_ROOT}/platform-tools/adb" "$@" |
| 17 } |
| 18 else |
| 19 echo 'adb missing' |
| 20 exit 2 |
| 21 fi |
| 22 fi |
| 23 phase1_timeout_seconds=15 |
| 24 phase2_timeout_seconds=60 |
| 25 package="$1" |
| 26 filename="$(date '+%H%M%S').skp" |
| 27 remote_path="/data/data/${package}/cache/${filename}" |
| 28 local_path="$(date '+%Y-%m-%d_%H%M%S')_${package}.skp" |
| 29 key='debug.hwui.capture_frame_as_skp' |
| 30 adb shell "setprop '${key}' '${remote_path}'" |
| 31 spin() { |
| 32 case "$spin" in |
| 33 1) printf '\b|';; |
| 34 2) printf '\b\\';; |
| 35 3) printf '\b-';; |
| 36 *) printf '\b/';; |
| 37 esac |
| 38 spin=$(( ( ${spin:-0} + 1 ) % 4 )) |
| 39 sleep $1 |
| 40 } |
| 41 |
| 42 banner() { |
| 43 printf '\n=====================\n' |
| 44 printf ' %s' "$*" |
| 45 printf '\n=====================\n' |
| 46 } |
| 47 banner '...WAITING...' |
| 48 adb_test_exist() { |
| 49 test '0' = "$(adb shell "test -e \"$1\"; echo \$?")"; |
| 50 } |
| 51 timeout=$(( $(date +%s) + $phase1_timeout_seconds)) |
| 52 while ! adb_test_exist "$remote_path"; do |
| 53 spin 0.05 |
| 54 if [ $(date +%s) -gt $timeout ] ; then |
| 55 printf '\bTimed out.\n' |
| 56 adb shell "setprop '${key}' ''" |
| 57 exit 3 |
| 58 fi |
| 59 done |
| 60 printf '\b' |
| 61 |
| 62 banner '...SAVING...' |
| 63 adb_test_file_nonzero() { |
| 64 # grab first byte of `du` output |
| 65 X="$(adb shell "du \"$1\" 2> /dev/null | dd bs=1 count=1 2> /dev/null")" |
| 66 test "$X" && test "$X" -ne 0 |
| 67 } |
| 68 #adb_filesize() { |
| 69 # adb shell "wc -c \"$1\"" 2> /dev/null | awk '{print $1}' |
| 70 #} |
| 71 timeout=$(( $(date +%s) + $phase2_timeout_seconds)) |
| 72 while ! adb_test_file_nonzero "$remote_path"; do |
| 73 spin 0.05 |
| 74 if [ $(date +%s) -gt $timeout ] ; then |
| 75 printf '\bTimed out.\n' |
| 76 adb shell "setprop '${key}' ''" |
| 77 exit 3 |
| 78 fi |
| 79 done |
| 80 printf '\b' |
| 81 |
| 82 adb shell "setprop '${key}' ''" |
| 83 |
| 84 i=0; while [ $i -lt 10 ]; do spin 0.10; i=$(($i + 1)); done; echo |
| 85 |
| 86 adb pull "$remote_path" "$local_path" |
| 87 if ! [ -f "$local_path" ] ; then |
| 88 printf "something went wrong with `adb pull`." |
| 89 exit 4 |
| 90 fi |
| 91 adb shell rm "$remote_path" |
| 92 printf '\nSKP saved to file:\n %s\n\n' "$local_path" |
OLD | NEW |