1#!/bin/bash
2#
3# Copyright 2018, The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18source "$DIR/lib/common"
19
20launch_application() {
21  local package="$1"
22  local activity="$2"
23
24  # if there's any $s inside of the activity name, it needs to be escaped to \$.
25  # example '.app.honeycomb.Shell$HomeActivity'
26  # if the $ is not escaped, adb shell will try to evaluate $HomeActivity to a variable.
27  activity=${activity//\$/\\$}
28
29  local am_output="$(adb shell am start -S -W "$package"/"$activity")"
30  verbose_print adb shell am start -S -W "$package"/"$activity"
31  if [[ $? -ne 0 ]]; then
32    echo "am start failed" >&2
33
34    return 1
35  fi
36
37  # for everything else use the am start "TotalTime" output.
38  verbose_print "$am_output"
39  local total_time="$(echo "$am_output" | grep 'TotalTime:' | sed 's/TotalTime: //g')"
40  verbose_print "total time: $total_time"
41
42  # TODO: Extract alternative metrics such as the #reportFullyDrawn.
43
44  echo "$total_time"
45}
46
47launch_application "$@"
48