-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_android.repy
62 lines (48 loc) · 1.81 KB
/
test_android.repy
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
"""
test_sensors.repy -- trying to use the SL4A JSON bridge to read sensors
Yanyan Zhuang
Change log:
v 0.0.2, 20140103
Initial experiment, based on the Apache-licensed code in
/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/android.py
"""
dy_import_module_symbols("sensorutility")
dy_import_module_symbols("android")
if callfunc=="initialize":
try:
ap_port = int(callargs[0])
except:
# Not castable (-> ValueError) or missing at all (-> IndexError)
usage()
exitall()
# set up connection to sl4a
sl4a_socket = openconnection("127.0.0.1", ap_port, "127.0.0.1", 12345, 5)
android_method_list_no_para = android_get_method_list_no_para()
log(android_method_list_no_para, '\n')
android_method_list = android_get_method_list()
log(android_method_list, '\n')
mycontext['id'] = 0
for methodname in android_method_list_no_para:
log('\n', methodname)
current = getruntime()
send_rpc_request(sl4a_socket, methodname, mycontext['id'])
log(get_rpc_response(sl4a_socket, 5))
log("time: ", str(getruntime()-current) + '\n')
sleep(1)
mycontext['id'] += 1
methodname = "makeToast"
mycontext['id'] += 1
log('\n', methodname)
current = getruntime()
send_rpc_request(sl4a_socket, methodname, mycontext['id'], "Hello world...")
log(get_rpc_response(sl4a_socket, 5))
log("time: ", str(getruntime()-current) + '\n')
methodname = "vibrate"
mycontext['id'] += 1
log('\n', methodname)
current = getruntime()
# vibrate for 3 secs (3000 ms)
send_rpc_request(sl4a_socket, methodname, mycontext['id'], 3000)
log(get_rpc_response(sl4a_socket, 5))
log("time: ", str(getruntime()-current) + '\n')
sl4a_socket.close()