You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #!/bin/bash
  2. # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  3. #
  4. # Use of this source code is governed by a BSD-style license
  5. # that can be found in the LICENSE file in the root of the source
  6. # tree. An additional intellectual property rights grant can be found
  7. # in the file PATENTS. All contributing project authors may
  8. # be found in the AUTHORS file in the root of the source tree.
  9. # Utility functions to be used by perf_setup.sh.
  10. # Contains helper methods and functions that wraps usage of adb.
  11. function error() {
  12. echo "[ERROR] "$@"" >&2
  13. }
  14. function warning() {
  15. echo "[WARNING] "$@"" >&1
  16. }
  17. function ok() {
  18. echo "[OK] "$@"" >&1
  19. }
  20. function abs_path {
  21. (cd $1; pwd)
  22. }
  23. function is_set() {
  24. local var="$1"
  25. [[ -n "${var}" ]]
  26. }
  27. function is_file() {
  28. local file="$1"
  29. [[ -f "${file}" ]]
  30. }
  31. function is_not_file() {
  32. local file="$1"
  33. [[ ! -f "${file}" ]]
  34. }
  35. function is_dir() {
  36. local dir="$1"
  37. [[ -d "${dir}" ]]
  38. }
  39. function is_not_dir() {
  40. local dir="$1"
  41. [[ ! -d "${dir}" ]]
  42. }
  43. # Adds (prepends) the PATH environment variable while avoid duplicates.
  44. function path_add() {
  45. case ":${PATH:=$1}:" in
  46. *:$1:*) ;;
  47. *) PATH="$1:$PATH" ;;
  48. esac
  49. }
  50. # Removes a path from the PATH environment variable using search-and-replace
  51. # parameter expansion.
  52. function path_remove {
  53. local path="$1"
  54. # Substitute first occurrence of ":path" in PATH with an empty string.
  55. # Deletes instances in the middle or at the end.
  56. PATH=${PATH/":$path"/}
  57. # Substitute first occurrence of "path:" in PATH with an empty string.
  58. # Delete instances at the beginning.
  59. PATH=${PATH/"$path:"/}
  60. }
  61. # Returns the process ID (PID) of the process that corresponds to the
  62. # application name given as input parameter.
  63. function find_app_pid() {
  64. local app_name="$1"
  65. adb shell ps | grep "${app_name}" | awk '{print $2}'
  66. }
  67. function app_is_installed() {
  68. local app_name="$1"
  69. local installed_app_name=$(adb shell pm list packages \
  70. | grep "${app_name}" | awk -F':' '{print $2}')
  71. is_set "${installed_app_name}" \
  72. && [[ "${installed_app_name}" = "${app_name}" ]]
  73. }
  74. function app_is_running() {
  75. local app_name="$1"
  76. local app_pid=$(find_app_pid "${app_name}")
  77. is_set "${app_pid}"
  78. }
  79. function app_start() {
  80. local app_name="$1"
  81. adb shell am start \
  82. -n "${app_name}/.ConnectActivity" \
  83. -a android.intent.action.MAIN
  84. }
  85. function app_stop() {
  86. local app_name="$1"
  87. adb shell am force-stop "${app_name}"
  88. }
  89. function app_uninstall() {
  90. local app_name="$1"
  91. adb uninstall "${app_name}"
  92. }
  93. function dev_arch() {
  94. adb shell uname -m
  95. }
  96. function dev_ls() {
  97. local dir="$1"
  98. adb shell ls "${dir}"
  99. }
  100. # Returns true if exactly on device is connected.
  101. function one_device_connected() {
  102. [[ $(adb devices | wc -l) = 3 ]]
  103. }
  104. # Returns true if device is rooted.
  105. function image_is_root() {
  106. [[ $(adb shell getprop ro.build.type) = "userdebug" ]]
  107. }
  108. # Returns true if device is not rooted.
  109. function image_is_not_root() {
  110. [[ $(adb shell getprop ro.build.type) = "user" ]]
  111. }
  112. # Returns true if adb is not already running as root.
  113. # Should only be called on rooted devices.
  114. function adb_has_no_root_permissions() {
  115. [[ $(adb shell getprop service.adb.root) = 0 ]]
  116. }
  117. # Android devices may disable profiling by default. We must enable it.
  118. function enable_profiling() {
  119. adb shell setprop security.perf_harden 0
  120. }
  121. # To make the report of symbols on device successful, we need to execute
  122. # `echo 0 >/proc/sys/kernel/kptr_restrict`.
  123. # Only needed if we run report commands on the same machine as we run
  124. # record commands.
  125. function enable_report_symbols() {
  126. adb shell "echo 0 > /proc/sys/kernel/kptr_restrict"
  127. }