From 973a2dcd6a62a8e12840b84442b71a198ab191f4 Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Fri, 14 Sep 2018 16:27:53 -0700 Subject: [PATCH] startop: app_startup script fixes for youtube/chrome Fix remote_pkill function to work on multiple pids, this was breaking chrome (which has 3 pids). Fix activity inference to the "$pkg/$activity" pattern where previously it could accidentally parse the wrong token. Fix app launching to handle activities with '$' in the name which adb shell treated as a variable. Test: manual Change-Id: Ifc9a72f1b9bb5e1416c7602f27f4614efd003849 --- .../scripts/app_startup/force_compiler_filter | 36 ++--------------- .../scripts/app_startup/launch_application | 6 +++ startop/scripts/app_startup/lib/common | 39 +++++++++++++++++++ .../scripts/app_startup/run_app_with_prefetch | 17 -------- 4 files changed, 48 insertions(+), 50 deletions(-) diff --git a/startop/scripts/app_startup/force_compiler_filter b/startop/scripts/app_startup/force_compiler_filter index 78e915bb4d53c..08f983d92bea1 100755 --- a/startop/scripts/app_startup/force_compiler_filter +++ b/startop/scripts/app_startup/force_compiler_filter @@ -100,36 +100,6 @@ parse_arguments() { fi } -get_activity_name() { - local package="$1" - local action_key="android.intent.action.MAIN:" - - local activity_line="$(adb shell cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.LAUNCHER | grep "$package")" - verbose_print $activity_line - IFS="/" read -a array <<< "$activity_line" - local activity_name="${array[1]}" - echo "$activity_name" - #adb shell am start "$package/$activity_name" -} - -remote_pidof() { - local procname="$1" - adb shell ps | grep "$procname" | awk '{print $2;}' -} - -remote_pkill() { - local procname="$1" - shift - - local the_pids=$(remote_pidof "$procname") - local pid - - for pid in $the_pids; do - verbose_print adb shell kill "$@" "$pid" - adb shell kill "$@" "$pid" - done -} - force_package_compilation() { local arg_compiler_filter="$1" local arg_package="$2" @@ -150,13 +120,13 @@ main() { # screen needs to be unlocked in order to run an app "$DIR"/unlock_screen - am_output="$(adb shell am start -S -W "$package"/"$activity")" + local output=$("$DIR"/launch_application "$package" "$activity") if [[ $? -ne 0 ]]; then - echo "am start failed" >&2 + echo "launching application failed" >&2 exit 1 fi - verbose_print "$am_output" + verbose_print "$output" # give some time for app startup to complete. # this is supposed to be an upper bound for measuring startup time. sleep "$wait_time" diff --git a/startop/scripts/app_startup/launch_application b/startop/scripts/app_startup/launch_application index bc4ec51d6d083..8a68e50161904 100755 --- a/startop/scripts/app_startup/launch_application +++ b/startop/scripts/app_startup/launch_application @@ -20,6 +20,12 @@ source "$DIR/lib/common" launch_application() { local package="$1" local activity="$2" + + # if there's any $s inside of the activity name, it needs to be escaped to \$. + # example '.app.honeycomb.Shell$HomeActivity' + # if the $ is not escaped, adb shell will try to evaluate $HomeActivity to a variable. + activity=${activity//\$/\\$} + local am_output="$(adb shell am start -S -W "$package"/"$activity")" verbose_print adb shell am start -S -W "$package"/"$activity" if [[ $? -ne 0 ]]; then diff --git a/startop/scripts/app_startup/lib/common b/startop/scripts/app_startup/lib/common index 4d5a53e4bb0cc..043d8550b64b5 100755 --- a/startop/scripts/app_startup/lib/common +++ b/startop/scripts/app_startup/lib/common @@ -12,3 +12,42 @@ verbose_print() { echo "$@" >&2 fi } + +remote_pidof() { + local procname="$1" + adb shell ps | grep "$procname" | awk '{print $2;}' +} + +remote_pkill() { + local procname="$1" + shift + + local the_pids=$(remote_pidof "$procname") + local pid + + for pid in $the_pids; do + verbose_print adb shell kill "$@" "$pid" + adb shell kill "$@" "$pid" + done +} + +get_activity_name() { + local package="$1" + local action_key="android.intent.action.MAIN:" + + # Example query-activities output being parsed: + # + # Activity #14: + # priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=true + # com.google.android.videos/com.google.android.youtube.videos.EntryPoint + # Activity #15: + # priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=true + # com.google.android.youtube/.app.honeycomb.Shell$HomeActivity + + # Given package 'com.google.android.youtube' return '.app.honeycomb.Shell$HomeActivity' + + local activity_line="$(adb shell cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.LAUNCHER | grep "$package/")" + IFS="/" read -a array <<< "$activity_line" + local activity_name="${array[1]}" + echo "$activity_name" +} diff --git a/startop/scripts/app_startup/run_app_with_prefetch b/startop/scripts/app_startup/run_app_with_prefetch index ce63ff9586136..56bffa85eb90e 100755 --- a/startop/scripts/app_startup/run_app_with_prefetch +++ b/startop/scripts/app_startup/run_app_with_prefetch @@ -111,18 +111,6 @@ echo_to_output_file() { echo "$@" } -get_activity_name() { - local package="$1" - local action_key="android.intent.action.MAIN:" - - local activity_line="$(adb shell cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.LAUNCHER | grep "$package")" - #echo $activity_line - IFS="/" read -a array <<< "$activity_line" - local activity_name="${array[1]}" - echo "$activity_name" - #adb shell am start "$package/$activity_name" -} - find_package_path() { local pkg="$1" @@ -133,11 +121,6 @@ find_package_path() { echo "$res" } -remote_pkill() { - local what="$1" - adb shell "for i in $(pid $what); do kill \$i; done" -} - # Main entry point if [[ $# -eq 0 ]]; then usage