summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2018-09-14 16:27:53 -0700
committerIgor Murashkin <iam@google.com>2018-09-14 16:27:53 -0700
commit973a2dcd6a62a8e12840b84442b71a198ab191f4 (patch)
tree1049492a59926aac0c4f9043651791b791af8e2b
parentb622e783ca34f5e67eab8b91ae48ef8f5badc1df (diff)
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
-rwxr-xr-xstartop/scripts/app_startup/force_compiler_filter36
-rwxr-xr-xstartop/scripts/app_startup/launch_application6
-rwxr-xr-xstartop/scripts/app_startup/lib/common39
-rwxr-xr-xstartop/scripts/app_startup/run_app_with_prefetch17
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 78e915bb4d53..08f983d92bea 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 bc4ec51d6d08..8a68e5016190 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 4d5a53e4bb0c..043d8550b64b 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 ce63ff958613..56bffa85eb90 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