blob: 043d8550b64b59af5b032a80c1dd99f36ad600c1 [file] [log] [blame]
Igor Murashkin25f394d2018-09-11 16:37:18 -07001#!/bin/bash
2
3if [[ -z $ANDROID_BUILD_TOP ]]; then
4 echo "Please run source build/envsetup.sh first" >&2
5 exit 1
6fi
7
8source $ANDROID_BUILD_TOP/build/envsetup.sh
9
10verbose_print() {
11 if [[ "$verbose" == "y" ]]; then
12 echo "$@" >&2
13 fi
14}
Igor Murashkin973a2dc2018-09-14 16:27:53 -070015
16remote_pidof() {
17 local procname="$1"
18 adb shell ps | grep "$procname" | awk '{print $2;}'
19}
20
21remote_pkill() {
22 local procname="$1"
23 shift
24
25 local the_pids=$(remote_pidof "$procname")
26 local pid
27
28 for pid in $the_pids; do
29 verbose_print adb shell kill "$@" "$pid"
30 adb shell kill "$@" "$pid"
31 done
32}
33
34get_activity_name() {
35 local package="$1"
36 local action_key="android.intent.action.MAIN:"
37
38 # Example query-activities output being parsed:
39 #
40 # Activity #14:
41 # priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=true
42 # com.google.android.videos/com.google.android.youtube.videos.EntryPoint
43 # Activity #15:
44 # priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=true
45 # com.google.android.youtube/.app.honeycomb.Shell$HomeActivity
46
47 # Given package 'com.google.android.youtube' return '.app.honeycomb.Shell$HomeActivity'
48
49 local activity_line="$(adb shell cmd package query-activities --brief -a android.intent.action.MAIN -c android.intent.category.LAUNCHER | grep "$package/")"
50 IFS="/" read -a array <<< "$activity_line"
51 local activity_name="${array[1]}"
52 echo "$activity_name"
53}