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
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user