forked from dtmilano/AndroidViewClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump
More file actions
executable file
·128 lines (114 loc) · 3.92 KB
/
dump
File metadata and controls
executable file
·128 lines (114 loc) · 3.92 KB
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
128
#! /usr/bin/env python
'''
Copyright (C) 2012 Diego Torres Milano
Created on Feb 3, 2012
@author: diego
'''
__version__ = '4.5.2'
import sys
import os
import getopt
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
HELP = 'help'
VERBOSE = 'verbose'
IGNORE_SECURE_DEVICE = 'ignore-secure-device'
FORCE_VIEW_SERVER_USE = 'force-view-server-use'
DO_NOT_START_VIEW_SERVER = 'do-not-start-view-server'
DO_NOT_IGNORE_UIAUTOMATOR_KILLED = 'do-not-ignore-uiautomator-killed'
WINDOW = 'window'
UNIQUE_ID = 'uniqueId'
POSITION = 'position'
CONTENT_DESCRIPTION = 'content-description'
CENTER = 'center'
MAP = {'i':ViewClient.TRAVERSE_CITUI, UNIQUE_ID:ViewClient.TRAVERSE_CITUI,
'x':ViewClient.TRAVERSE_CITPS, POSITION:ViewClient.TRAVERSE_CITPS,
'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD,
'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC,
}
USAGE = 'usage: %s [OPTION]... [serialno]'
SHORT_OPTS = 'HVIFSkw:ixdc'
LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE,
DO_NOT_START_VIEW_SERVER, DO_NOT_IGNORE_UIAUTOMATOR_KILLED, WINDOW + '=',
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER]
LONG_OPTS_ARG = {WINDOW: 'WINDOW'}
OPTS_HELP = {
'H': 'prints this help',
'V': 'verbose comments',
'I': 'ignore secure device',
'F': 'force view server use (even if UiAutomator present)',
'S': 'don\'t start ViewServer',
'k': 'don\'t ignore UiAutomator killed',
'w': 'dump WINDOW content (default: -1, all windows)',
'i': 'dump View unique IDs',
'x': 'dump View positions',
'd': 'dump View content descriptions',
'c': 'dump View centers'
}
def shortAndLongOptions():
'''
@return: the list of corresponding (short-option, long-option) tuples
'''
short_opts = SHORT_OPTS.replace(':', '')
if len(short_opts) != len(LONG_OPTS):
raise Exception('There is a mismatch between short and long options')
t = tuple(short_opts) + tuple(LONG_OPTS)
l2 = len(t)/2
sl = []
for i in range(l2):
sl.append((t[i], t[i+l2]))
return sl
def usage(exitVal=1):
print >> sys.stderr, USAGE % progname
print >> sys.stderr, "Try '%s --help' for more information." % progname
sys.exit(exitVal)
def help():
print >> sys.stderr, USAGE % progname
print >> sys.stderr
print >> sys.stderr, "Options:"
for so, lo in shortAndLongOptions():
o = ' -%c, --%s' % (so, lo)
if lo[-1] == '=':
o += LONG_OPTS_ARG[lo[:-1]]
try:
o = '%-34s %-45s' % (o, OPTS_HELP[so])
except:
pass
print >> sys.stderr, o
sys.exit(0)
# __main__
progname = os.path.basename(sys.argv[0])
try:
opts, args = getopt.getopt(sys.argv[1:], SHORT_OPTS, LONG_OPTS)
sys.argv[1:] = args
except getopt.GetoptError, e:
print >>sys.stderr, 'ERROR:', str(e)
usage()
kwargs1 = {VERBOSE: False, 'ignoresecuredevice': False}
kwargs2 = {'forceviewserveruse': False, 'startviewserver': True, 'autodump': False, 'ignoreuiautomatorkilled': True}
options = {WINDOW: -1}
transform = ViewClient.TRAVERSE_CIT
for o, a in opts:
o = o.strip('-')
if o in ['H', HELP]:
help()
elif o in ['V', VERBOSE]:
kwargs1[VERBOSE] = True
elif o in ['I', IGNORE_SECURE_DEVICE]:
kwargs1['ignoresecuredevice'] = True
elif o in ['F', FORCE_VIEW_SERVER_USE]:
kwargs2['forceviewserveruse'] = True
elif o in ['S', DO_NOT_START_VIEW_SERVER]:
kwargs2['startviewserver'] = False
elif o in ['k', DO_NOT_IGNORE_UIAUTOMATOR_KILLED]:
kwargs2['ignoreuiautomatorkilled'] = False
elif o in ['w', WINDOW]:
options[WINDOW] = a
else:
transform = MAP[o]
vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2)
vc.dump(window=options[WINDOW])
vc.traverse(transform=transform)