-
Notifications
You must be signed in to change notification settings - Fork 22
/
haos
127 lines (112 loc) · 3.79 KB
/
haos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Script to start "uiautomator" on the device
#
# The script does a couple of things:
# * Use an alternative dalvik cache when running as non-root. Jar file needs
# to be dexopt'd to run in Dalvik. For plain jar files, this is done at first
# use. shell user does not have write permission to default system Dalvik
# cache so we redirect to an alternative cache
# * special processing for subcommand 'runtest':
# * '--nohup' allows process continue to run even if parent process that
# started it has already terminated. We parse for this parameter and set
# signal trap. This is useful for testing with USB disconnected
# * all jar files that the test classes resides in, or dependent on are
# provided on command line and exported to CLASSPATH environment variable
# before starting the Java code. This offloads the task of class loading
# and resolving of cross jar class dependency to Dalvik
# * all other subcommand or options are directly passed into Java code for
# further parsing
export run_base=/data/local/tmp
export base=/system
# if not running as root, trick dalvik into using an alternative dex cache
if [ ${USER_ID} -ne 0 ]; then
tmp_cache=${run_base}/dalvik-cache
if [ ! -d ${tmp_cache} ]; then
mkdir -p ${tmp_cache}
fi
export ANDROID_DATA=${run_base}
fi
# take first parameter as the command
cmd=${1}
if [ -z "${1}" ]; then
cmd="help"
fi
# strip the command parameter
if [ -n "${1}" ]; then
shift
fi
CLASSPATH=/system/framework/android.test.runner.jar:${base}/framework/uiautomator.jar
# eventually args will be what get passed down to Java code
args=
# we also pass the list of jar files, so we can extract class names for tests
# if they are not explicitly specified
jars=
# special case pre-processing for 'runtest' command
if [ "${cmd}" == "runtest" ]; then
# first parse the jar paths
while [ true ]; do
if [ -z "${1}" ]; then
echo "Error: more parameters expected for runtest; please see usage for details"
cmd="help"
break
fi
jar=${1}
if [ "${1:0:1}" = "-" ]; then
# we are done with jars, starting with parameters now
break
fi
# if relative path, append the default path prefix
if [ "${1:0:1}" != "/" ]; then
jar=${run_base}/${1}
fi
# about to add the file to class path, check if it's valid
if [ ! -f ${jar} ]; then
echo "Error: ${jar} does not exist"
# force to print help message
cmd="help"
break
fi
jars=${jars}:${jar}
# done processing current arg, moving on
shift
done
# look for --nohup: if found, consume it and trap SIG_HUP, otherwise just
# append the arg to args
while [ -n "${1}" ]; do
if [ "${1}" = "--nohup" ]; then
trap "" HUP
shift
else
args="${args} ${1}"
shift
fi
done
else
# if cmd is not 'runtest', just take the rest of the args
args=${@}
fi
args="${cmd} ${args}"
if [ -n "${jars}" ]; then
args="${args} -e jars ${jars}"
fi
CLASSPATH=${CLASSPATH}:${jars}:/data/local/tmp/android-support-v4-haos.jar
export CLASSPATH
cmd="app_process ${base}/bin nsl.stg.uiautomator.cmds.MyLauncher ${args}"
#date > /sdcard/cmd
#echo $CLASSPATH >> /sdcard/cmd
#echo $cmd >> /sdcard/cmd
exec $cmd