From 6ee3e9d1f293c2d51736b8ba053e66bd873ad232 Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Wed, 22 Mar 2017 13:38:34 +0800 Subject: automated: android: set and use environmental variable ANDROID_SERIAL When ANDROID_SERIAL set, we don't need to use '-s' to specify device serial no. any more. Change-Id: Ide4951c6ab68806a6241b38c3bf001e2e4e15eab Signed-off-by: Chase Qi --- automated/lib/android-test-lib | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'automated/lib') diff --git a/automated/lib/android-test-lib b/automated/lib/android-test-lib index 8677fea..3fe6831 100755 --- a/automated/lib/android-test-lib +++ b/automated/lib/android-test-lib @@ -12,26 +12,26 @@ install_latest_adb() { initialize_adb() { which lava-lxc-device-add && lava-lxc-device-add adb start-server - adb wait-for-device adb devices - if [ -z "${SN}" ]; then + if [ -z "${ANDROID_SERIAL}" ]; then number="$(adb devices | grep -wc 'device')" if [ "${number}" -gt 1 ]; then - warn_msg "Device not specified; define SN or use '-s'" - error_msg "More than one device or emulator found" + error_msg "More than one device or emulator found! Please set ANDROID_SERIAL from test script." elif [ "${number}" -eq 1 ]; then - SN="$(adb get-serialno)" - export SN + ANDROID_SERIAL="$(adb get-serialno)" else error_msg "Device NOT found" fi fi + export ANDROID_SERIAL + info_msg "Default adb device: ${ANDROID_SERIAL}" + adb wait-for-device - if adb -s "${SN}" shell echo "Testing adb connectivity"; then - info_msg "Connected to device ${SN} successfully" + if adb shell echo "Testing adb connectivity"; then + info_msg "Connected to device ${ANDROID_SERIAL} successfully" else - error_msg "Unable to connect to device ${SN}" + error_msg "Unable to connect to device ${ANDROID_SERIAL}" fi } @@ -50,7 +50,7 @@ wait_boot_completed() { boot_completed=false while [ "$(date +%s)" -lt "$end" ]; do - if adb -s "${SN}" shell getprop sys.boot_completed | grep "1"; then + if adb shell getprop sys.boot_completed | grep "1"; then boot_completed=true break else @@ -72,7 +72,7 @@ wait_homescreen() { homescreen_displayed=false while [ "$(date +%s)" -lt "$end" ]; do - if adb -s "${SN}" logcat -sd ActivityManager:I | grep "Displayed com.android.launcher"; then + if adb logcat -sd ActivityManager:I | grep "Displayed com.android.launcher"; then homescreen_displayed=true break else @@ -90,7 +90,7 @@ wait_homescreen() { detect_abi() { # "| tr -d '\r'" is needed here, refer to the below issue. # https://code.google.com/p/android/issues/detail?id=2482 - abi="$(adb -s "${SN}" shell uname -m | tr -d '\r')" + abi="$(adb shell uname -m | tr -d '\r')" case $abi in armv7|armv7l|armv7el|armv7lh) abi="armeabi" ;; arm64|armv8|arm64-v8a|aarch64) abi="arm64" ;; @@ -108,18 +108,18 @@ install() { file_path="$1" file_name="$(basename "${file_path}")" - if adb -s "${SN}" shell mount | grep system | grep -q ro; then + if adb shell mount | grep system | grep -q ro; then # Remounts the /system partition on the device read-write info_msg "/system partition is read-only, remounting it read-write..." # Because of https://bugs.linaro.org/show_bug.cgi?id=2888, this # function wouldn't work in LAVA v2 LXC until the bug get addressed. adb root - adb -s "${SN}" remount + adb remount fi info_msg "Installing ${file_name}" - adb -s "${SN}" push "${file_path}" "/system/bin/" - adb -s "${SN}" shell chmod 755 "/system/bin/${file_name}" + adb push "${file_path}" "/system/bin/" + adb shell chmod 755 "/system/bin/${file_name}" } adb_push() { @@ -127,10 +127,10 @@ adb_push() { local="$1" remote="$2" - adb -s "${SN}" shell mkdir -p "${remote}" - info_msg "Pushing ${local} to devcie ${SN}" - adb -s "${SN}" push "${local}" "${remote}" - adb -s "${SN}" shell chmod -R 755 "${remote}" + adb shell mkdir -p "${remote}" + info_msg "Pushing ${local} to devcie ${ANDROID_SERIAL}" + adb push "${local}" "${remote}" + adb shell chmod -R 755 "${remote}" } adb_pull() { @@ -138,6 +138,6 @@ adb_pull() { remote="$1" local="$2" - info_msg "Pulling ${remote} from devcie ${SN}" - adb -s "${SN}" pull "${remote}" "${local}" + info_msg "Pulling ${remote} from devcie ${ANDROID_SERIAL}" + adb pull "${remote}" "${local}" } -- cgit v1.2.3