-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadbtest.rb
129 lines (93 loc) · 2.28 KB
/
adbtest.rb
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
require "open3"
require "thread"
class AdbShell
attr_accessor :chkcount
attr_writer :chkon, :chkstr
@chkstr=nil, @chkcount=0, @chkon=false
def initialize( adbname, adbpath="D:\\Phone\\adb-log\\")
@adbname,@adbpath = adbname,adbpath
end
def openShell
@stdin, @stdout, @stderr, @wait_thr=Open3.popen3( @adbpath+'adb shell')
@exitAdb = false
@qerr = Queue.new
@errthd = Thread.new do
Thread.current.abort_on_exception = true
while ( !@exitAdb ) do
line = @stderr.gets
@qerr.push(line)
end
@qerr.push :stderr_done
end
@qout = Queue.new
@outthd = Thread.new do
Thread.current.abort_on_exception = true
while ( !@exitAdb ) do
line = @stdout.gets
@qout.push(line)
end
@qout.push :stdout_done
end
@outProcThd = Thread.new do
Thread.current.abort_on_exception = true
while ( true ) do
if ( stuff = @qout.pop )
if @chkon
if stuff.index( @chkstr )
@chkcount+=1
end
end
break if stuff == :stdout_done
end
end
end
@errProcThd = Thread.new do
Thread.current.abort_on_exception = true
while ( true ) do
if ( emsg = @qerr.pop )
puts emsg
break if emsg == :stderr_done
end
end
end
end
def runCmd( cmd, longcmd=false )
@longcmd = longcmd
@stdin.puts( cmd )
end
def closeShell
if !@longcmd
@stdin.puts('exit')
else
@stdin.puts('\x03')
end
@exitAdb=true
end
end
logcmd='logcat -v time -b radio'
dialcmd='service call phone 2 s16 "18975184038"'
hangupcmd='input keyevent KEYCODE_ENDCALL'
gsmDialing='CLCC: 1,0,2'
gsmAlerting='CLCC: 1,0,3'
gsmCallingStatus=[ gsmDialing, gsmAlerting ]
logsh = AdbShell.new('log')
logsh.openShell
logsh.runCmd( logcmd,true )
dialsh = AdbShell.new('dial')
dialsh.openShell
logsh.chkstr=gsmCallingStatus[1]
logsh.chkcount=0
logsh.chkon=true
dialsh.runCmd( dialcmd )
t0 = Time.now
while (1>logsh.chkcount ) do
break if Time.now - t0 > 5
end
puts Time.now - t0
dialsh.runCmd( hangupcmd )
logsh.chkon=false
puts logsh.chkcount
logsh.chkcount=0
#gets
logsh.closeShell
dialsh.closeShell